Class MockLowLevelHttpResponse
java.lang.Object
com.google.api.client.http.LowLevelHttpResponse
com.google.api.client.testing.http.MockLowLevelHttpResponse
- Since:
- 1.3
- Author:
- Yaniv Inbar
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a header to the response.voidDefault implementation does nothing, but subclasses may override to attempt to abort the connection or release allocated system resources for this connection.Returns the HTTP response content input stream ornullfor none.Returns the content encoding (for example"gzip") ornullfor none.longReturns the content length or0for none.final StringReturns the content type ornullfor none.intReturns the number of HTTP response headers.getHeaderName(int index) Returns the HTTP response header name at the given zero-based index.Returns the list of header names of HTTP response.getHeaderValue(int index) Returns the HTTP response header value at the given zero-based index.Returns the list of header values of HTTP response.Returns the HTTP reason phrase ornullfor none.intReturns the response status code or<=0for none.Returns the response status line ornullfor none.booleanReturns whetherdisconnect()has been called.setContent(byte[] byteContent) Sets the response content to the given byte array.setContent(InputStream content) Sets the input stream content of HTTP response ornullfor none.setContent(String stringContent) Sets the response content to the given content string.setContentEncoding(String contentEncoding) Sets the content encoding ornullfor none.setContentLength(long contentLength) Sets the content length or-1for unknown.setContentType(String contentType) Sets the content type of HTTP response ornullfor none.setHeaderNames(List<String> headerNames) Sets the list of header names of HTTP response.setHeaderValues(List<String> headerValues) Sets the list of header values of HTTP response.setReasonPhrase(String reasonPhrase) Sets the HTTP reason phrase ornullfor none.setStatusCode(int statusCode) Sets the status code of HTTP response.Sets the content tonulland the content length to 0.
-
Constructor Details
-
MockLowLevelHttpResponse
public MockLowLevelHttpResponse()
-
-
Method Details
-
addHeader
Adds a header to the response.- Parameters:
name- header namevalue- header value
-
setContent
Sets the response content to the given content string.If the input string is
null, it will set the content tonull. Else, it will useTestableByteArrayInputStreamwith the UTF-8 encoded string content.- Parameters:
stringContent- content string ornullfor none
-
setContent
Sets the response content to the given byte array.- Parameters:
byteContent- content byte array, ornullfor none.If the byte array is
null, the method invokessetZeroContent(). Otherwise,byteContentis wrapped in aTestableByteArrayInputStreamand becomes thisMockLowLevelHttpResponse's contents.- Since:
- 1.18
-
setZeroContent
Sets the content tonulland the content length to 0. Note that the result will have a content length header whose value is 0.- Since:
- 1.18
-
getContent
Description copied from class:LowLevelHttpResponseReturns the HTTP response content input stream ornullfor none.- Specified by:
getContentin classLowLevelHttpResponse- Throws:
IOException- I/O exception
-
getContentEncoding
Description copied from class:LowLevelHttpResponseReturns the content encoding (for example"gzip") ornullfor none.- Specified by:
getContentEncodingin classLowLevelHttpResponse
-
getContentLength
public long getContentLength()Description copied from class:LowLevelHttpResponseReturns the content length or0for none.- Specified by:
getContentLengthin classLowLevelHttpResponse
-
getContentType
Description copied from class:LowLevelHttpResponseReturns the content type ornullfor none.- Specified by:
getContentTypein classLowLevelHttpResponse
-
getHeaderCount
public int getHeaderCount()Description copied from class:LowLevelHttpResponseReturns the number of HTTP response headers.Note that multiple headers of the same name need to be supported, in which case each header value is treated as a separate header.
- Specified by:
getHeaderCountin classLowLevelHttpResponse
-
getHeaderName
Description copied from class:LowLevelHttpResponseReturns the HTTP response header name at the given zero-based index.- Specified by:
getHeaderNamein classLowLevelHttpResponse
-
getHeaderValue
Description copied from class:LowLevelHttpResponseReturns the HTTP response header value at the given zero-based index.- Specified by:
getHeaderValuein classLowLevelHttpResponse
-
getReasonPhrase
Description copied from class:LowLevelHttpResponseReturns the HTTP reason phrase ornullfor none.- Specified by:
getReasonPhrasein classLowLevelHttpResponse
-
getStatusCode
public int getStatusCode()Description copied from class:LowLevelHttpResponseReturns the response status code or<=0for none.- Specified by:
getStatusCodein classLowLevelHttpResponse
-
getStatusLine
Description copied from class:LowLevelHttpResponseReturns the response status line ornullfor none.- Specified by:
getStatusLinein classLowLevelHttpResponse
-
getHeaderNames
-
setHeaderNames
Sets the list of header names of HTTP response.Default value is an empty list.
- Since:
- 1.5
-
getHeaderValues
-
setHeaderValues
Sets the list of header values of HTTP response.- Since:
- 1.5
-
setContent
Sets the input stream content of HTTP response ornullfor none.- Since:
- 1.5
-
setContentType
Sets the content type of HTTP response ornullfor none.- Since:
- 1.5
-
setContentEncoding
Sets the content encoding ornullfor none.- Since:
- 1.5
-
setContentLength
Sets the content length or-1for unknown.By default it is
-1.- Since:
- 1.5
-
setStatusCode
Sets the status code of HTTP response.Default value is
200.- Since:
- 1.5
-
setReasonPhrase
Sets the HTTP reason phrase ornullfor none.- Since:
- 1.6
-
disconnect
Description copied from class:LowLevelHttpResponseDefault implementation does nothing, but subclasses may override to attempt to abort the connection or release allocated system resources for this connection.- Overrides:
disconnectin classLowLevelHttpResponse- Throws:
IOException- I/O exception
-
isDisconnected
-