@Beta public class MockLowLevelHttpResponse extends LowLevelHttpResponse
| Constructor and Description |
|---|
MockLowLevelHttpResponse() |
| Modifier and Type | Method and Description |
|---|---|
MockLowLevelHttpResponse |
addHeader(String name,
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.
|
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<String> |
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<String> |
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 content)
Sets the input stream content of HTTP response or
null for none. |
MockLowLevelHttpResponse |
setContent(String stringContent)
Sets the response content to the given content string.
|
MockLowLevelHttpResponse |
setContentEncoding(String contentEncoding)
Sets the content encoding or
null for none. |
MockLowLevelHttpResponse |
setContentLength(long contentLength)
Sets the content length or
-1 for unknown. |
MockLowLevelHttpResponse |
setContentType(String contentType)
Sets the content type of HTTP response or
null for none. |
MockLowLevelHttpResponse |
setHeaderNames(List<String> headerNames)
Sets the list of header names of HTTP response.
|
MockLowLevelHttpResponse |
setHeaderValues(List<String> headerValues)
Sets the list of header values of HTTP response.
|
MockLowLevelHttpResponse |
setReasonPhrase(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(String name, String value)
name - header namevalue - header valuepublic MockLowLevelHttpResponse setContent(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 InputStream getContent() throws IOException
LowLevelHttpResponsenull for none.getContent in class LowLevelHttpResponseIOException - I/O exceptionpublic String getContentEncoding()
LowLevelHttpResponse"gzip") or null for none.getContentEncoding in class LowLevelHttpResponsepublic long getContentLength()
LowLevelHttpResponse0 for none.getContentLength in class LowLevelHttpResponsepublic final 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 String getHeaderName(int index)
LowLevelHttpResponsegetHeaderName in class LowLevelHttpResponsepublic String getHeaderValue(int index)
LowLevelHttpResponsegetHeaderValue in class LowLevelHttpResponsepublic String getReasonPhrase()
LowLevelHttpResponsenull for none.getReasonPhrase in class LowLevelHttpResponsepublic int getStatusCode()
LowLevelHttpResponse<=0 for none.getStatusCode in class LowLevelHttpResponsepublic String getStatusLine()
LowLevelHttpResponsenull for none.getStatusLine in class LowLevelHttpResponsepublic final List<String> getHeaderNames()
public MockLowLevelHttpResponse setHeaderNames(List<String> headerNames)
Default value is an empty list.
public final List<String> getHeaderValues()
Default value is an empty list.
public MockLowLevelHttpResponse setHeaderValues(List<String> headerValues)
public MockLowLevelHttpResponse setContent(InputStream content)
null for none.public MockLowLevelHttpResponse setContentType(String contentType)
null for none.public MockLowLevelHttpResponse setContentEncoding(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(String reasonPhrase)
null for none.public void disconnect()
throws IOException
LowLevelHttpResponsedisconnect in class LowLevelHttpResponseIOException - I/O exceptionpublic boolean isDisconnected()
disconnect() has been called.Copyright © 2011–2025 Google. All rights reserved.