com.baidu.sapi2.http
类 BinaryHttpResponseHandler

java.lang.Object
  继承者 com.baidu.sapi2.http.AsyncHttpResponseHandler
      继承者 com.baidu.sapi2.http.BinaryHttpResponseHandler

public class BinaryHttpResponseHandler
extends AsyncHttpResponseHandler

Used to intercept and handle the responses from requests made using 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 :(
     }
 });
 


字段摘要
 
从类 com.baidu.sapi2.http.AsyncHttpResponseHandler 继承的字段
FAILURE_MESSAGE, FINISH_MESSAGE, START_MESSAGE, SUCCESS_MESSAGE
 
构造方法摘要
BinaryHttpResponseHandler()
          Creates a new BinaryHttpResponseHandler
BinaryHttpResponseHandler(String[] allowedContentTypes)
          Creates a new BinaryHttpResponseHandler, and overrides the default allowed content types with passed String array (hopefully) of content types.
 
方法摘要
protected  void handleFailureMessage(Throwable e)
           
protected  void handleMessage(android.os.Message msg)
           
protected  void handleSuccessMessage(int statusCode, byte[] responseBody)
           
 void onFailure(Throwable error, byte[] binaryData)
          已过时。  
 void onSuccess(byte[] binaryData)
          Fired when a request returns successfully, override to handle in your own code
 void onSuccess(int statusCode, byte[] binaryData)
          Fired when a request returns successfully, override to handle in your own code
protected  void sendFailureMessage(Throwable e, byte[] responseBody)
           
protected  void sendSuccessMessage(int statusCode, byte[] responseBody)
           
 
从类 com.baidu.sapi2.http.AsyncHttpResponseHandler 继承的方法
handleFailureMessage, handleSuccessMessage, obtainMessage, onFailure, onFailure, onFinish, onStart, onSuccess, onSuccess, sendFailureMessage, sendFinishMessage, sendMessage, sendStartMessage, sendSuccessMessage
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

BinaryHttpResponseHandler

public BinaryHttpResponseHandler()
Creates a new BinaryHttpResponseHandler


BinaryHttpResponseHandler

public BinaryHttpResponseHandler(String[] allowedContentTypes)
Creates a new BinaryHttpResponseHandler, and overrides the default allowed content types with passed String array (hopefully) of content types.

方法详细信息

onSuccess

public void onSuccess(byte[] binaryData)
Fired when a request returns successfully, override to handle in your own code

参数:
binaryData - the body of the HTTP response from the server

onSuccess

public void onSuccess(int statusCode,
                      byte[] binaryData)
Fired when a request returns successfully, override to handle in your own code

参数:
statusCode - the status code of the response
binaryData - the body of the HTTP response from the server

onFailure

public void onFailure(Throwable error,
                      byte[] binaryData)
已过时。 

Fired when a request fails to complete, override to handle in your own code

参数:
error - the underlying cause of the failure
binaryData - the response body, if any

sendSuccessMessage

protected void sendSuccessMessage(int statusCode,
                                  byte[] responseBody)

sendFailureMessage

protected void sendFailureMessage(Throwable e,
                                  byte[] responseBody)
覆盖:
AsyncHttpResponseHandler 中的 sendFailureMessage

handleSuccessMessage

protected void handleSuccessMessage(int statusCode,
                                    byte[] responseBody)

handleFailureMessage

protected void handleFailureMessage(Throwable e)

handleMessage

protected void handleMessage(android.os.Message msg)
覆盖:
AsyncHttpResponseHandler 中的 handleMessage


Copyright © 2013. All Rights Reserved.