public class RestResponse
extends java.lang.Object
| Constructor and Description |
|---|
RestResponse(Response response)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
asBytes() |
java.io.InputStream |
asInputStream()
Streams the response content.
|
JSONArray |
asJSONArray()
JSONArray is built the first time the method is called.
|
JSONObject |
asJSONObject()
JSONObject is built the first time the method is called.
|
java.lang.String |
asString()
String is built the first time the method is called.
|
void |
consume()
Fully consume response entity content and closes content stream
Must be called before returning control to the UI thread
|
void |
consumeQuietly()
Fully consume a response and swallow any exceptions thrown during the process.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getAllHeaders()
Returns all headers associated with this response.
|
java.lang.String |
getContentType()
Return content type
|
Response |
getRawResponse()
Method to get the "raw" response (i.e.
|
int |
getStatusCode() |
boolean |
isSuccess() |
static boolean |
isSuccess(int statusCode) |
java.lang.String |
toString() |
public RestResponse(Response response)
response - okHttp Response object.public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getAllHeaders()
public int getStatusCode()
public boolean isSuccess()
public static boolean isSuccess(int statusCode)
public void consume()
throws java.io.IOException
java.io.IOExceptionpublic void consumeQuietly()
consume()public byte[] asBytes()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getContentType()
public java.lang.String asString()
throws java.io.IOException
java.io.IOExceptionpublic JSONObject asJSONObject()
throws JSONException,
java.io.IOException
JSONExceptionjava.io.IOExceptionpublic JSONArray asJSONArray()
throws JSONException,
java.io.IOException
JSONExceptionjava.io.IOExceptionpublic java.io.InputStream asInputStream()
throws java.io.IOException
InputStream.close(),
or calling consume() to discard the contents.
>
If the response is consumed as a stream, asBytes() will return an empty array,
asString() will return an empty string and both asJSONArray() and
asJSONObject() will throw exceptions.
InputStream from the response contentjava.io.IOException - if the stream could not be created or has already been consumedpublic Response getRawResponse()
Responsepublic java.lang.String toString()
toString in class java.lang.Object