@Beta public class MockLowLevelHttpResponse extends LowLevelHttpResponse
| Constructor and Description |
|---|
MockLowLevelHttpResponse() |
| Modifier and Type | Method and Description |
|---|---|
MockLowLevelHttpResponse |
addHeader(java.lang.String name,
java.lang.String value)
Adds a header to the response.
|
void |
disconnect()
Default implementation does nothing, but subclasses may override to attempt to abort the
connection or release allocated system resources for this connection.
|
java.io.InputStream |
getContent()
Returns the HTTP response content input stream or
null for none. |
java.lang.String |
getContentEncoding()
Returns the content encoding (for example
"gzip") or null for none. |
long |
getContentLength()
Returns the content length or
0 for none. |
java.lang.String |
getContentType()
Returns the content type or
null for none. |
int |
getHeaderCount()
Returns the number of HTTP response headers.
|
java.lang.String |
getHeaderName(int index)
Returns the HTTP response header name at the given zero-based index.
|
java.util.List<java.lang.String> |
getHeaderNames()
Returns the list of header names of HTTP response.
|
java.lang.String |
getHeaderValue(int index)
Returns the HTTP response header value at the given zero-based index.
|
java.util.List<java.lang.String> |
getHeaderValues()
Returns the list of header values of HTTP response.
|
java.lang.String |
getReasonPhrase()
Returns the HTTP reason phrase or
null for none. |
int |
getStatusCode()
Returns the response status code or
<=0 for none. |
java.lang.String |
getStatusLine()
Returns the response status line or
null for none. |
boolean |
isDisconnected()
Returns whether
disconnect() has been called. |
MockLowLevelHttpResponse |
setContent(byte[] byteContent)
Sets the response content to the given byte array.
|
MockLowLevelHttpResponse |
setContent(java.io.InputStream content)
Sets the input stream content of HTTP response or
null for none. |
MockLowLevelHttpResponse |
setContent(java.lang.String stringContent)
Sets the response content to the given content string.
|
MockLowLevelHttpResponse |
setContentEncoding(java.lang.String contentEncoding)
Sets the content encoding or
null for none. |
MockLowLevelHttpResponse |
setContentLength(long contentLength)
Sets the content length or
-1 for unknown. |
MockLowLevelHttpResponse |
setContentType(java.lang.String contentType)
Sets the content type of HTTP response or
null for none. |
MockLowLevelHttpResponse |
setHeaderNames(java.util.List<java.lang.String> headerNames)
Sets the list of header names of HTTP response.
|
MockLowLevelHttpResponse |
setHeaderValues(java.util.List<java.lang.String> headerValues)
Sets the list of header values of HTTP response.
|
MockLowLevelHttpResponse |
setReasonPhrase(java.lang.String reasonPhrase)
Sets the HTTP reason phrase or
null for none. |
MockLowLevelHttpResponse |
setStatusCode(int statusCode)
Sets the status code of HTTP response.
|
MockLowLevelHttpResponse |
setZeroContent()
Sets the content to
null and the content length to 0. |
public MockLowLevelHttpResponse addHeader(java.lang.String name, java.lang.String value)
name - header namevalue - header valuepublic MockLowLevelHttpResponse setContent(java.lang.String stringContent)
If the input string is null, it will set the content to null. Else, it will use
TestableByteArrayInputStream with the UTF-8 encoded string content.
stringContent - content string or null for nonepublic MockLowLevelHttpResponse setContent(byte[] byteContent)
byteContent - content byte array, or null for none.
If the byte array is null, the method invokes setZeroContent().
Otherwise, byteContent is wrapped in a TestableByteArrayInputStream
and becomes this MockLowLevelHttpResponse's contents.
public MockLowLevelHttpResponse setZeroContent()
null and the content length to 0. Note that
the result will have a content length header whose value is 0.public java.io.InputStream getContent()
throws java.io.IOException
LowLevelHttpResponsenull for none.getContent in class LowLevelHttpResponsejava.io.IOException - I/O exceptionpublic java.lang.String getContentEncoding()
LowLevelHttpResponse"gzip") or null for none.getContentEncoding in class LowLevelHttpResponsepublic long getContentLength()
LowLevelHttpResponse0 for none.getContentLength in class LowLevelHttpResponsepublic final java.lang.String getContentType()
LowLevelHttpResponsenull for none.getContentType in class LowLevelHttpResponsepublic int getHeaderCount()
LowLevelHttpResponseNote that multiple headers of the same name need to be supported, in which case each header value is treated as a separate header.
getHeaderCount in class LowLevelHttpResponsepublic java.lang.String getHeaderName(int index)
LowLevelHttpResponsegetHeaderName in class LowLevelHttpResponsepublic java.lang.String getHeaderValue(int index)
LowLevelHttpResponsegetHeaderValue in class LowLevelHttpResponsepublic java.lang.String getReasonPhrase()
LowLevelHttpResponsenull for none.getReasonPhrase in class LowLevelHttpResponsepublic int getStatusCode()
LowLevelHttpResponse<=0 for none.getStatusCode in class LowLevelHttpResponsepublic java.lang.String getStatusLine()
LowLevelHttpResponsenull for none.getStatusLine in class LowLevelHttpResponsepublic final java.util.List<java.lang.String> getHeaderNames()
public MockLowLevelHttpResponse setHeaderNames(java.util.List<java.lang.String> headerNames)
Default value is an empty list.
public final java.util.List<java.lang.String> getHeaderValues()
Default value is an empty list.
public MockLowLevelHttpResponse setHeaderValues(java.util.List<java.lang.String> headerValues)
public MockLowLevelHttpResponse setContent(java.io.InputStream content)
null for none.public MockLowLevelHttpResponse setContentType(java.lang.String contentType)
null for none.public MockLowLevelHttpResponse setContentEncoding(java.lang.String contentEncoding)
null for none.public MockLowLevelHttpResponse setContentLength(long contentLength)
-1 for unknown.
By default it is -1.
public MockLowLevelHttpResponse setStatusCode(int statusCode)
Default value is 200.
public MockLowLevelHttpResponse setReasonPhrase(java.lang.String reasonPhrase)
null for none.public void disconnect()
throws java.io.IOException
LowLevelHttpResponsedisconnect in class LowLevelHttpResponsejava.io.IOException - I/O exceptionpublic boolean isDisconnected()
disconnect() has been called.Copyright © 2011-2018 Google. All Rights Reserved.