public abstract class BinaryHttpResponseHandler extends AsyncHttpResponseHandler
AsyncHttpClient.
Receives response body as byte array with a content-type whitelist. (e.g. checks Content-Type
against allowed list, Content-length). For example:
AsyncHttpClient client = new AsyncHttpClient();
String[] allowedTypes = new String[] { "image/png" };
client.get("https://www.example.com/image.png", new BinaryHttpResponseHandler(allowedTypes) {
@Override
public void onSuccess(byte[] imageData) {
// Successfully got a response
}
@Override
public void onFailure(Throwable e, byte[] imageData) {
// Response failed :(
}
});
BUFFER_SIZE, CANCEL_MESSAGE, DEFAULT_CHARSET, FAILURE_MESSAGE, FINISH_MESSAGE, PROGRESS_MESSAGE, RETRY_MESSAGE, START_MESSAGE, SUCCESS_MESSAGE, UTF8_BOM| Constructor and Description |
|---|
BinaryHttpResponseHandler()
Creates a new BinaryHttpResponseHandler
|
BinaryHttpResponseHandler(java.lang.String[] allowedContentTypes)
Creates a new BinaryHttpResponseHandler, and overrides the default allowed content types with
passed String array (hopefully) of content types.
|
BinaryHttpResponseHandler(java.lang.String[] allowedContentTypes,
android.os.Looper looper)
Creates a new BinaryHttpResponseHandler with a user-supplied looper, and overrides the default allowed content types with
passed String array (hopefully) of content types.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String[] |
getAllowedContentTypes()
Method can be overriden to return allowed content types, can be sometimes better than passing
data in constructor
|
abstract void |
onFailure(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
byte[] binaryData,
java.lang.Throwable error)
Fired when a request fails to complete, override to handle in your own code
|
abstract void |
onSuccess(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
byte[] binaryData)
Fired when a request returns successfully, override to handle in your own code
|
void |
sendResponseMessage(cz.msebera.android.httpclient.HttpResponse response)
Returns data whether request completed successfully
|
getCharset, getRequestHeaders, getRequestURI, getTag, getUsePoolThread, getUseSynchronousMode, handleMessage, obtainMessage, onCancel, onFinish, onPostProcessResponse, onPreProcessResponse, onProgress, onRetry, onStart, onUserException, postRunnable, sendCancelMessage, sendFailureMessage, sendFinishMessage, sendMessage, sendProgressMessage, sendRetryMessage, sendStartMessage, sendSuccessMessage, setCharset, setRequestHeaders, setRequestURI, setTag, setUsePoolThread, setUseSynchronousModepublic BinaryHttpResponseHandler()
public BinaryHttpResponseHandler(java.lang.String[] allowedContentTypes)
allowedContentTypes - content types array, eg. 'image/jpeg' or pattern '.*'public BinaryHttpResponseHandler(java.lang.String[] allowedContentTypes,
android.os.Looper looper)
allowedContentTypes - content types array, eg. 'image/jpeg' or pattern '.*'looper - The looper to work withpublic java.lang.String[] getAllowedContentTypes()
public abstract void onSuccess(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
byte[] binaryData)
AsyncHttpResponseHandleronSuccess in class AsyncHttpResponseHandlerstatusCode - the status code of the responseheaders - return headers, if anybinaryData - the body of the HTTP response from the serverpublic abstract void onFailure(int statusCode,
cz.msebera.android.httpclient.Header[] headers,
byte[] binaryData,
java.lang.Throwable error)
AsyncHttpResponseHandleronFailure in class AsyncHttpResponseHandlerstatusCode - return HTTP status codeheaders - return headers, if anybinaryData - the response body, if anyerror - the underlying cause of the failurepublic final void sendResponseMessage(cz.msebera.android.httpclient.HttpResponse response)
throws java.io.IOException
ResponseHandlerInterfacesendResponseMessage in interface ResponseHandlerInterfacesendResponseMessage in class AsyncHttpResponseHandlerresponse - HttpResponse object with datajava.io.IOException - if retrieving data from response fails