public class BoxHttpResponse
extends java.lang.Object
All responses from the REST API are read using this class or one of its subclasses. This class wraps HttpURLConnection in order to provide a simpler interface that can automatically handle various conditions specific
to Box's API. When a response is constructed, it will throw a BoxException if the response from the API
was an error. Therefore every BoxAPIResponse instance is guaranteed to represent a successful response.
This class usually isn't instantiated directly, but is instead returned after calling BoxRequest.send().
| Modifier and Type | Field and Description |
|---|---|
protected java.net.HttpURLConnection |
mConnection |
protected java.lang.String |
mContentType |
protected int |
mResponseCode |
| Constructor and Description |
|---|
BoxHttpResponse(java.net.HttpURLConnection connection)
Constructs a BoxAPIResponse using an HttpURLConnection.
|
| Modifier and Type | Method and Description |
|---|---|
void |
disconnect()
Disconnects this response from the server and frees up any network resources.
|
java.io.InputStream |
getBody()
Gets an InputStream for reading this response's body.
|
java.io.InputStream |
getBody(ProgressListener listener)
Gets an InputStream for reading this response's body which will report its read progress to a ProgressListener.
|
int |
getContentLength()
Gets the length of this response's body as indicated by the "Content-Length" header.
|
java.lang.String |
getContentType() |
java.net.HttpURLConnection |
getHttpURLConnection()
Gets the HTTP URL connection for this response.
|
int |
getResponseCode()
Gets the response code returned by the API.
|
java.lang.String |
getStringBody()
Returns a string representation of this response's body.
|
void |
open()
Open connection to the resource.
|
protected final java.net.HttpURLConnection mConnection
protected int mResponseCode
protected java.lang.String mContentType
public BoxHttpResponse(java.net.HttpURLConnection connection)
connection - a connection that has already sent a request to the API.public void open()
throws java.io.IOException
java.io.IOException - if an error occurs connecting to server.public int getResponseCode()
public int getContentLength()
public java.lang.String getContentType()
public java.io.InputStream getBody()
throws BoxException
BoxException - thrown if there was an issue getting the body including network issues.public java.io.InputStream getBody(ProgressListener listener) throws BoxException
listener - a listener for monitoring the read progress of the body.BoxException - thrown if there was an issue getting the body including network issues.public void disconnect()
throws BoxException
BoxException - thrown if there was an issue closing the connection.public java.lang.String getStringBody()
throws BoxException
BoxException - thrown if there was an issue getting the body.public java.net.HttpURLConnection getHttpURLConnection()