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 class
NetHttpResponse.SizeValidatingInputStream
A wrapper arround the baseInputStream
that validates EOF returned by the read calls.
-
Field Summary
Fields Modifier and Type Field Description private java.net.HttpURLConnection
connection
private java.util.ArrayList<java.lang.String>
headerNames
private java.util.ArrayList<java.lang.String>
headerValues
private int
responseCode
private java.lang.String
responseMessage
-
Constructor Summary
Constructors Constructor Description NetHttpResponse(java.net.HttpURLConnection connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
disconnect()
Closes the connection to the HTTP server.java.io.InputStream
getContent()
Returns the HTTP response content input stream ornull
for none.java.lang.String
getContentEncoding()
Returns the content encoding (for example"gzip"
) ornull
for none.long
getContentLength()
Returns the content length or0
for none.java.lang.String
getContentType()
Returns the content type ornull
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.lang.String
getHeaderValue(int index)
Returns the HTTP response header value at the given zero-based index.java.lang.String
getReasonPhrase()
Returns the HTTP reason phrase ornull
for none.int
getStatusCode()
Returns the response status code or<=0
for none.java.lang.String
getStatusLine()
Returns the response status line ornull
for 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:LowLevelHttpResponse
Returns the response status code or<=0
for none.- Specified by:
getStatusCode
in classLowLevelHttpResponse
-
getContent
public java.io.InputStream getContent() throws java.io.IOException
Returns the HTTP response content input stream ornull
for 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 anIOException
will 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:
getContent
in classLowLevelHttpResponse
- Throws:
java.io.IOException
- I/O exception
-
getContentEncoding
public java.lang.String getContentEncoding()
Description copied from class:LowLevelHttpResponse
Returns the content encoding (for example"gzip"
) ornull
for none.- Specified by:
getContentEncoding
in classLowLevelHttpResponse
-
getContentLength
public long getContentLength()
Description copied from class:LowLevelHttpResponse
Returns the content length or0
for none.- Specified by:
getContentLength
in classLowLevelHttpResponse
-
getContentType
public java.lang.String getContentType()
Description copied from class:LowLevelHttpResponse
Returns the content type ornull
for none.- Specified by:
getContentType
in classLowLevelHttpResponse
-
getReasonPhrase
public java.lang.String getReasonPhrase()
Description copied from class:LowLevelHttpResponse
Returns the HTTP reason phrase ornull
for none.- Specified by:
getReasonPhrase
in classLowLevelHttpResponse
-
getStatusLine
public java.lang.String getStatusLine()
Description copied from class:LowLevelHttpResponse
Returns the response status line ornull
for none.- Specified by:
getStatusLine
in classLowLevelHttpResponse
-
getHeaderCount
public int getHeaderCount()
Description copied from class:LowLevelHttpResponse
Returns 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:
getHeaderCount
in classLowLevelHttpResponse
-
getHeaderName
public java.lang.String getHeaderName(int index)
Description copied from class:LowLevelHttpResponse
Returns the HTTP response header name at the given zero-based index.- Specified by:
getHeaderName
in classLowLevelHttpResponse
-
getHeaderValue
public java.lang.String getHeaderValue(int index)
Description copied from class:LowLevelHttpResponse
Returns the HTTP response header value at the given zero-based index.- Specified by:
getHeaderValue
in classLowLevelHttpResponse
-
disconnect
public void disconnect()
Closes the connection to the HTTP server.- Overrides:
disconnect
in classLowLevelHttpResponse
- Since:
- 1.4
-
-