public class BoxAPIResponse extends Object implements Closeable
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(int responseCode,
String requestMethod,
String requestUrl,
Map<String,List<String>> headers)
Constructs a BoxAPIResponse with a http response code and response headers.
|
BoxAPIResponse(int code,
String requestMethod,
String requestUrl,
Map<String,List<String>> headers,
InputStream body,
String contentType,
long contentLength) |
Modifier and Type | Method and Description |
---|---|
protected String |
bodyToString()
Returns a string representation of this response's body.
|
void |
close() |
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.
|
String |
getHeaderField(String fieldName)
Gets the value of the given header field.
|
Map<String,List<String>> |
getHeaders() |
protected String |
getRequestMethod() |
protected String |
getRequestUrl() |
int |
getResponseCode()
Gets the response code returned by the API.
|
String |
toString() |
public BoxAPIResponse()
public BoxAPIResponse(int responseCode, String requestMethod, String requestUrl, Map<String,List<String>> headers)
responseCode
- http response codeheaders
- map of headerspublic BoxAPIResponse(int code, String requestMethod, String requestUrl, Map<String,List<String>> headers, InputStream body, String contentType, long contentLength)
public int getResponseCode()
public long getContentLength()
public String getHeaderField(String fieldName)
fieldName
- name of the header field.public InputStream getBody()
public InputStream getBody(ProgressListener listener)
listener
- a listener for monitoring the read progress of the body.public void disconnect()
public Map<String,List<String>> getHeaders()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
protected String bodyToString()
protected String getRequestMethod()
protected String getRequestUrl()