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("http://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| 构造器和说明 |
|---|
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.
|
| 限定符和类型 | 方法和说明 |
|---|---|
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,
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,
Header[] headers,
byte[] binaryData)
Fired when a request returns successfully, override to handle in your own code
|
void |
sendResponseMessage(HttpResponse response)
Returns data whether request completed successfully
|
getCharset, getRequestHeaders, getRequestURI, getUsePoolThread, getUseSynchronousMode, handleMessage, obtainMessage, onCancel, onFinish, onPostProcessResponse, onPreProcessResponse, onProgress, onRetry, onStart, onUserException, postRunnable, sendCancelMessage, sendFailureMessage, sendFinishMessage, sendMessage, sendProgressMessage, sendRetryMessage, sendStartMessage, sendSuccessMessage, setCharset, setRequestHeaders, setRequestURI, setUsePoolThread, setUseSynchronousModepublic BinaryHttpResponseHandler()
public BinaryHttpResponseHandler(java.lang.String[] allowedContentTypes)
allowedContentTypes - content types array, eg. 'image/jpeg' or pattern '.*'public java.lang.String[] getAllowedContentTypes()
public abstract void onSuccess(int statusCode,
Header[] headers,
byte[] binaryData)
AsyncHttpResponseHandleronSuccess 在类中 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,
Header[] headers,
byte[] binaryData,
java.lang.Throwable error)
AsyncHttpResponseHandleronFailure 在类中 AsyncHttpResponseHandlerstatusCode - return HTTP status codeheaders - return headers, if anybinaryData - the response body, if anyerror - the underlying cause of the failurepublic final void sendResponseMessage(HttpResponse response)
throws java.io.IOException
ResponseHandlerInterfacesendResponseMessage 在接口中 ResponseHandlerInterfacesendResponseMessage 在类中 AsyncHttpResponseHandlerresponse - HttpResponse object with datajava.io.IOException - if retrieving data from response fails