@Beta public class MockLowLevelHttpResponse extends LowLevelHttpResponse
| Constructor and Description |
|---|
MockLowLevelHttpResponse()
|
| Modifier and Type | Method and Description |
|---|---|
MockLowLevelHttpResponse |
addHeader(String
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.
|
InputStream |
getContent()
Returns the HTTP response content input stream or
null for none.
|
String |
getContentEncoding()
Returns the content encoding (for example
"gzip") or
null for none.
|
long |
getContentLength()
Returns the content length or
0 for none.
|
String |
getContentType()
Returns the content type or
null for none.
|
int |
getHeaderCount()
Returns the number of HTTP response headers.
|
String |
getHeaderName(int index)
Returns the HTTP response header name at the given zero-based index.
|
List |
getHeaderNames()
Returns the list of header names of HTTP response.
|
String |
getHeaderValue(int index)
Returns the HTTP response header value at the given zero-based index.
|
List |
getHeaderValues()
Returns the list of header values of HTTP response.
|
String |
getReasonPhrase()
Returns the HTTP reason phrase or
null for none.
|
int |
getStatusCode()
Returns the response status code or
<=0 for none.
|
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(InputStream
Sets the input stream content of HTTP response or
null for none.
|
MockLowLevelHttpResponse |
setContent(String
Sets the response content to the given content string.
|
MockLowLevelHttpResponse |
setContentEncoding(String
Sets the content encoding or
null for none.
|
MockLowLevelHttpResponse |
setContentLength(long contentLength)
Sets the content length or
-1 for unknown.
|
MockLowLevelHttpResponse |
setContentType(String
Sets the content type of HTTP response or
null for none.
|
MockLowLevelHttpResponse |
setHeaderNames(List
Sets the list of header names of HTTP response.
|
MockLowLevelHttpResponse |
setHeaderValues(List
Sets the list of header values of HTTP response.
|
MockLowLevelHttpResponse |
setReasonPhrase(String
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 MockLowLevelHttpResponseaddHeader(String name, String value)
name - header name
value - header value
public MockLowLevelHttpResponsesetContent(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 none
public MockLowLevelHttpResponsesetContent(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 MockLowLevelHttpResponsesetZeroContent()
null and the content length to 0. Note that the result will have a content length header whose value is 0.
public InputStreamgetContent() throws IOException
LowLevelHttpResponse
null for none.
getContent in class
LowLevelHttpResponse
IOException - I/O exception
public StringgetContentEncoding()
LowLevelHttpResponse
"gzip") or
null for none.
public long getContentLength()
LowLevelHttpResponse
0 for none.
public final StringgetContentType()
LowLevelHttpResponse
null for none.
public int getHeaderCount()
LowLevelHttpResponse
Note that multiple headers of the same name need to be supported, in which case each header value is treated as a separate header.
public StringgetHeaderName(int index)
LowLevelHttpResponse
public StringgetHeaderValue(int index)
LowLevelHttpResponse
public StringgetReasonPhrase()
LowLevelHttpResponse
null for none.
public int getStatusCode()
LowLevelHttpResponse
<=0 for none.
public StringgetStatusLine()
LowLevelHttpResponse
null for none.
public final List<String > getHeaderNames()
public MockLowLevelHttpResponsesetHeaderNames(List <String > headerNames)
Default value is an empty list.
public final List<String > getHeaderValues()
Default value is an empty list.
public MockLowLevelHttpResponsesetHeaderValues(List <String > headerValues)
public MockLowLevelHttpResponsesetContent(InputStream content)
null for none.
public MockLowLevelHttpResponsesetContentType(String contentType)
null for none.
public MockLowLevelHttpResponsesetContentEncoding(String contentEncoding)
null for none.
public MockLowLevelHttpResponsesetContentLength(long contentLength)
-1 for unknown.
By default it is -1.
public MockLowLevelHttpResponsesetStatusCode(int statusCode)
Default value is 200.
public MockLowLevelHttpResponsesetReasonPhrase(String reasonPhrase)
null for none.
public void disconnect()
throws IOException
LowLevelHttpResponse
disconnect in class
LowLevelHttpResponse
IOException - I/O exception
public boolean isDisconnected()
disconnect() has been called.