public class BoxAPIResponse extends 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 contructed, it will throw a BoxAPIException
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 BoxAPIRequest.send()
.
Constructor and Description |
---|
BoxAPIResponse()
Constructs an empty BoxAPIResponse without an associated HttpURLConnection.
|
BoxAPIResponse(HttpURLConnection connection)
Constructs a BoxAPIResponse using an HttpURLConnection.
|
Modifier and Type | Method and Description |
---|---|
protected String |
bodyToString()
Returns a string representation of this response's body.
|
void |
disconnect()
Disconnects this response from the server and frees up any network resources.
|
InputStream |
getBody()
Gets an InputStream for reading this response's body.
|
InputStream |
getBody(ProgressListener listener)
Gets an InputStream for reading this response's body which will report its read progress to a ProgressListener.
|
long |
getContentLength()
Gets the length of this response's body as indicated by the "Content-Length" header.
|
int |
getResponseCode()
Gets the response code returned by the API.
|
String |
toString() |
public BoxAPIResponse()
public BoxAPIResponse(HttpURLConnection connection)
connection
- a connection that has already sent a request to the API.public int getResponseCode()
public long getContentLength()
public InputStream getBody()
public InputStream getBody(ProgressListener listener)
listener
- a listener for monitoring the read progress of the body.public void disconnect()
protected String bodyToString()