public abstract class AsyncHttpResponseHandler
extends java.lang.Object
onSend -> onPublishedUploadProgress -> onPublishedDownloadProgress -> beforeCallback -> onSuccess/onFailure -> beforeFinish -> onFinish
onPublishedDownloadProgress(byte[], int, long), onPublishedUploadProgress(byte[], int, long),
beforeCallback(), onSuccess(), and onFailure() all run in
the background thread. All your processing should be handled in one of those
4 methods and then either call to run on UI thread a new runnable, or handle
in onFinish() which runs on the UI thread
In order to get the content created from the response handler, you must
call getContent() which can be accessed in onSuccess() or
onFailure()| Constructor and Description |
|---|
AsyncHttpResponseHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
beforeCallback()
Called just before
onSuccess() |
void |
beforeFinish()
Called before
onFinish() |
abstract void |
generateContent()
Override this method to efficiently generate your content from any buffers you have have
used.
|
ConnectionInfo |
getConnectionInfo() |
abstract java.lang.Object |
getContent()
Gets the content generated from the
response.
|
void |
onBeginPublishedDownloadProgress(java.io.InputStream stream,
AsyncHttpClient.ClientExecutorTask client,
long totalLength)
Called when processing the response from a stream.
|
void |
onFailure()
Called when a response was not 2xx.
|
void |
onFinish()
Called when the streams have all finished, success or not
|
void |
onFinish(boolean failed)
Called when the streams have all finished, success or not
|
void |
onPublishedDownloadProgress(byte[] chunk,
int chunkLength,
long totalLength)
Called when a chunk has been downloaded from the request.
|
void |
onPublishedDownloadProgress(byte[] chunk,
int chunkLength,
long totalProcessed,
long totalLength)
Called when a chunk has been downloaded from the request.
|
void |
onPublishedDownloadProgressUI(long totalProcessed,
long totalLength)
Runs on the UI thread.
|
void |
onPublishedUploadProgress(byte[] chunk,
int chunkLength,
long totalLength)
Called when a chunk has been uploaded to the request.
|
void |
onPublishedUploadProgress(byte[] chunk,
int chunkLength,
long totalProcessed,
long totalLength)
Called when a chunk has been uploaded to the request.
|
void |
onPublishedUploadProgressUI(long totalProcessed,
long totalLength)
Runs on the UI thread.
|
void |
onSend()
Called when the connection is first made
|
abstract void |
onSuccess()
Processes the response from the stream.
|
public ConnectionInfo getConnectionInfo()
public void onSend()
public void onBeginPublishedDownloadProgress(java.io.InputStream stream,
AsyncHttpClient.ClientExecutorTask client,
long totalLength)
throws java.net.SocketTimeoutException,
java.lang.Exception
onPublishedDownloadProgress(byte[], int, long)stream - The response InputStreamclient - The client task. In order to call
onPublishedDownloadProgressUI(long, long), you must call
client.postPublishProgress(new Packet(int readCount, int totalLength, boolean isDownload))
This is required when displaying a progress indicator.totalLength - The total length of the streamjava.net.SocketTimeoutExceptionjava.lang.Exceptionpublic void onPublishedDownloadProgress(byte[] chunk,
int chunkLength,
long totalLength)
chunk - The chunk of data. This will be the null after the total amount has been downloaded.chunkLength - The length of the chunktotalLength - The total size of the request. note: This can be
-1 during download.public void onPublishedDownloadProgress(byte[] chunk,
int chunkLength,
long totalProcessed,
long totalLength)
chunk - The chunk of data. This will be the null after the total amount has been downloaded.chunkLength - The length of the chunktotalProcessed - The total amount of data processed from the request.totalLength - The total size of the request. note: This can be
-1 during download.public void onPublishedDownloadProgressUI(long totalProcessed,
long totalLength)
totalProcessed - The total processed sized of the requesttotalLength - The total length of the requestpublic void onPublishedUploadProgress(byte[] chunk,
int chunkLength,
long totalLength)
chunk - will be the total byte array when this is called.chunk - The chunk of datachunkLength - The length of the chunktotalLength - The total size of the request.public void onPublishedUploadProgress(byte[] chunk,
int chunkLength,
long totalProcessed,
long totalLength)
chunk - will be the total byte array when this is called.chunk - The chunk of datachunkLength - The length of the chunktotalProcessed - The total amount of data processed from the request.totalLength - The total size of the request.public void onPublishedUploadProgressUI(long totalProcessed,
long totalLength)
totalProcessed - The total processed sized of the requesttotalLength - The total length of the requestpublic void beforeCallback()
onSuccess()public abstract void generateContent()
onBeginPublishedDownloadProgress(java.io.InputStream, net.callumtaylor.asynchttp.AsyncHttpClient.ClientExecutorTask, long) has finishedpublic abstract java.lang.Object getContent()
public abstract void onSuccess()
public void onFailure()
public void beforeFinish()
onFinish()public void onFinish()
public void onFinish(boolean failed)
failed - If the stream failed or not. Useful to display any UI updates
here.