Class NetHttpResponse
- java.lang.Object
-
- com.google.api.client.http.LowLevelHttpResponse
-
- com.google.api.client.http.javanet.NetHttpResponse
-
final class NetHttpResponse extends LowLevelHttpResponse
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classNetHttpResponse.SizeValidatingInputStreamA wrapper arround the baseInputStreamthat validates EOF returned by the read calls.
-
Field Summary
Fields Modifier and Type Field Description private java.net.HttpURLConnectionconnectionprivate java.util.ArrayList<java.lang.String>headerNamesprivate java.util.ArrayList<java.lang.String>headerValuesprivate intresponseCodeprivate java.lang.StringresponseMessage
-
Constructor Summary
Constructors Constructor Description NetHttpResponse(java.net.HttpURLConnection connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisconnect()Closes the connection to the HTTP server.java.io.InputStreamgetContent()Returns the HTTP response content input stream ornullfor none.java.lang.StringgetContentEncoding()Returns the content encoding (for example"gzip") ornullfor none.longgetContentLength()Returns the content length or0for none.java.lang.StringgetContentType()Returns the content type ornullfor none.intgetHeaderCount()Returns the number of HTTP response headers.java.lang.StringgetHeaderName(int index)Returns the HTTP response header name at the given zero-based index.java.lang.StringgetHeaderValue(int index)Returns the HTTP response header value at the given zero-based index.java.lang.StringgetReasonPhrase()Returns the HTTP reason phrase ornullfor none.intgetStatusCode()Returns the response status code or<=0for none.java.lang.StringgetStatusLine()Returns the response status line ornullfor none.
-
-
-
Field Detail
-
connection
private final java.net.HttpURLConnection connection
-
responseCode
private final int responseCode
-
responseMessage
private final java.lang.String responseMessage
-
headerNames
private final java.util.ArrayList<java.lang.String> headerNames
-
headerValues
private final java.util.ArrayList<java.lang.String> headerValues
-
-
Method Detail
-
getStatusCode
public int getStatusCode()
Description copied from class:LowLevelHttpResponseReturns the response status code or<=0for none.- Specified by:
getStatusCodein classLowLevelHttpResponse
-
getContent
public java.io.InputStream getContent() throws java.io.IOExceptionReturns the HTTP response content input stream ornullfor none.Returns
URLConnection.getInputStream()when it doesn't throwIOException, otherwise it returnsHttpURLConnection.getErrorStream().Upgrade warning: in prior version 1.16
getContent()returnedURLConnection.getInputStream()only when the status code was successful. Starting with version 1.17 it returnsURLConnection.getInputStream()when it doesn't throwIOException, otherwise it returnsHttpURLConnection.getErrorStream()Upgrade warning: in versions prior to 1.20
getContent()returnedURLConnection.getInputStream()orHttpURLConnection.getErrorStream(), both of which silently returned -1 for read() calls when the connection got closed in the middle of receiving a response. This is highly likely a bug from JDK'sHttpURLConnection. Since version 1.20, the bytes read off the wire will be checked and anIOExceptionwill be thrown if the response is not fully delivered when the connection is closed by server for whatever reason, e.g., server restarts. Note though that this is a best-effort check: when the response is chunk encoded, we have to rely on the underlying HTTP library to behave correctly.- Specified by:
getContentin classLowLevelHttpResponse- Throws:
java.io.IOException- I/O exception
-
getContentEncoding
public java.lang.String 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
public java.lang.String getContentType()
Description copied from class:LowLevelHttpResponseReturns the content type ornullfor none.- Specified by:
getContentTypein classLowLevelHttpResponse
-
getReasonPhrase
public java.lang.String getReasonPhrase()
Description copied from class:LowLevelHttpResponseReturns the HTTP reason phrase ornullfor none.- Specified by:
getReasonPhrasein classLowLevelHttpResponse
-
getStatusLine
public java.lang.String getStatusLine()
Description copied from class:LowLevelHttpResponseReturns the response status line ornullfor none.- Specified by:
getStatusLinein 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
public java.lang.String getHeaderName(int index)
Description copied from class:LowLevelHttpResponseReturns the HTTP response header name at the given zero-based index.- Specified by:
getHeaderNamein classLowLevelHttpResponse
-
getHeaderValue
public java.lang.String getHeaderValue(int index)
Description copied from class:LowLevelHttpResponseReturns the HTTP response header value at the given zero-based index.- Specified by:
getHeaderValuein classLowLevelHttpResponse
-
disconnect
public void disconnect()
Closes the connection to the HTTP server.- Overrides:
disconnectin classLowLevelHttpResponse- Since:
- 1.4
-
-