com.google.api.client.http
Class HttpResponse

java.lang.Object
  extended by com.google.api.client.http.HttpResponse

public final class HttpResponse
extends Object

HTTP response.

Since:
1.0
Author:
Yaniv Inbar

Field Summary
 String contentEncoding
          Content encoding or null.
 String contentType
          Content type or null for none.
 boolean disableContentLogging
          Whether to disable response content logging during getContent() (unless Level.ALL is loggable which forces all logging).
 HttpHeaders headers
          HTTP headers.
 boolean isSuccessStatusCode
          Whether received a successful status code >= 200 && < 300.
 int statusCode
          Status code.
 String statusMessage
          Status message or null.
 HttpTransport transport
          HTTP transport.
 
Method Summary
 InputStream getContent()
          Returns the content of the HTTP response.
 HttpParser getParser()
          Returns the HTTP response content parser to use for the content type of this HTTP response or null for none.
 void ignore()
          Gets the content of the HTTP response from getContent() and ignores the content if there is any.
static boolean isSuccessStatusCode(int statusCode)
          Returns whether the given HTTP response status code is a success code >= 200 and < 300.
<T> T
parseAs(Class<T> dataClass)
          Parses the content of the HTTP response from getContent() and reads it into a data class of key/value pairs using the parser returned by getParser() .
 String parseAsString()
          Parses the content of the HTTP response from getContent() and reads it into a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contentEncoding

public final String contentEncoding
Content encoding or null.


contentType

public final String contentType
Content type or null for none.


headers

public final HttpHeaders headers
HTTP headers.

If a header name is used for multiple headers, only the last one is retained.

This field's value is instantiated using the same class as that of the HttpTransport.defaultHeaders.


isSuccessStatusCode

public final boolean isSuccessStatusCode
Whether received a successful status code >= 200 && < 300.


statusCode

public final int statusCode
Status code.


statusMessage

public final String statusMessage
Status message or null.


transport

public final HttpTransport transport
HTTP transport.


disableContentLogging

public boolean disableContentLogging
Whether to disable response content logging during getContent() (unless Level.ALL is loggable which forces all logging).

Useful for example if content has sensitive data such as an authentication token. Defaults to false.

Method Detail

getContent

public InputStream getContent()
                       throws IOException
Returns the content of the HTTP response.

The result is cached, so subsequent calls will be fast.

Returns:
input stream content of the HTTP response or null for none
Throws:
IOException - I/O exception

ignore

public void ignore()
            throws IOException
Gets the content of the HTTP response from getContent() and ignores the content if there is any.

Throws:
IOException - I/O exception

getParser

public HttpParser getParser()
Returns the HTTP response content parser to use for the content type of this HTTP response or null for none.


parseAs

public <T> T parseAs(Class<T> dataClass)
          throws IOException
Parses the content of the HTTP response from getContent() and reads it into a data class of key/value pairs using the parser returned by getParser() .

Returns:
parsed data class or null for no content
Throws:
IOException - I/O exception
IllegalArgumentException - if no parser is defined for the given content type or if there is no content type defined in the HTTP response

parseAsString

public String parseAsString()
                     throws IOException
Parses the content of the HTTP response from getContent() and reads it into a string.

Since this method returns "" for no content, a simpler check for no content is to check if getContent() is null.

Returns:
parsed string or "" for no content
Throws:
IOException - I/O exception

isSuccessStatusCode

public static boolean isSuccessStatusCode(int statusCode)
Returns whether the given HTTP response status code is a success code >= 200 and < 300.



Copyright © 2010-2011 Google. All Rights Reserved.