com.fitbit.api.client.http
Class Response

java.lang.Object
  extended by com.fitbit.api.client.http.Response

public class Response
extends Object

A data class representing HTTP Response

Author:
Yusuke Yamamoto - yusuke at mac.com

Field Summary
protected  InputStream is
           
protected  int statusCode
           
 
Constructor Summary
protected Response()
           
  Response(HttpURLConnection con)
           
 
Method Summary
 Document asDocument()
          Returns the response body as org.w3c.dom.Document.
Disconnects the internal HttpURLConnection silently.
 org.json.JSONArray asJSONArray()
          Returns the response body as org.json.JSONArray.
Disconnects the internal HttpURLConnection silently.
 org.json.JSONObject asJSONObject()
          Returns the response body as org.json.JSONObject.
Disconnects the internal HttpURLConnection silently.
 InputStreamReader asReader()
           
 InputStream asStream()
          Returns the response stream.
This method cannot be called after calling asString() or asDcoument()
It is suggested to call disconnect() after consuming the stream.
 String asString()
          Returns the response body as string.
Disconnects the internal HttpURLConnection silently.
 void disconnect()
           
 String getResponseHeader(String name)
           
 int getStatusCode()
           
 boolean isError()
           
 String toString()
           
static String unescape(String original)
          Unescape UTF-8 escaped characters to string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

statusCode

protected int statusCode

is

protected InputStream is
Constructor Detail

Response

public Response(HttpURLConnection con)
         throws IOException
Throws:
IOException

Response

protected Response()
Method Detail

getStatusCode

public int getStatusCode()

getResponseHeader

public String getResponseHeader(String name)

asStream

public InputStream asStream()
Returns the response stream.
This method cannot be called after calling asString() or asDcoument()
It is suggested to call disconnect() after consuming the stream.

Disconnects the internal HttpURLConnection silently.

Returns:
response body stream
Throws:
FitbitAPIException
See Also:
disconnect()

asString

public String asString()
                throws FitbitAPIException
Returns the response body as string.
Disconnects the internal HttpURLConnection silently.

Returns:
response body
Throws:
FitbitAPIException

asDocument

public Document asDocument()
                    throws FitbitAPIException
Returns the response body as org.w3c.dom.Document.
Disconnects the internal HttpURLConnection silently.

Returns:
response body as org.w3c.dom.Document
Throws:
FitbitAPIException

asJSONObject

public org.json.JSONObject asJSONObject()
                                 throws FitbitAPIException
Returns the response body as org.json.JSONObject.
Disconnects the internal HttpURLConnection silently.

Returns:
response body as org.json.JSONObject
Throws:
FitbitAPIException

asJSONArray

public org.json.JSONArray asJSONArray()
                               throws FitbitAPIException
Returns the response body as org.json.JSONArray.
Disconnects the internal HttpURLConnection silently.

Returns:
response body as org.json.JSONArray
Throws:
FitbitAPIException

asReader

public InputStreamReader asReader()

disconnect

public void disconnect()

unescape

public static String unescape(String original)
Unescape UTF-8 escaped characters to string.

Parameters:
original - The string to be unescaped.
Returns:
The unescaped string

toString

public String toString()
Overrides:
toString in class Object

isError

public boolean isError()


Copyright © 2012. All Rights Reserved.