public abstract class ResponseHandler<E> extends Object
onSend -> onByteChunkSent -> onByteChunkReceived -> beforeResponse -> onSuccess/onFailure -> beforeFinish -> onFinish
onByteChunkReceived(byte[], long, long, long), onByteChunkSent(byte[], long, long, long),
beforeResponse(), 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 |
|---|
ResponseHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
beforeFinish()
Called before
onFinish() |
void |
beforeResponse()
Called just before
onSuccess() |
abstract void |
generateContent()
Override this method to efficiently generate your content from any buffers you have have
used.
|
ConnectionInfo |
getConnectionInfo() |
abstract E |
getContent()
Gets the content generated from the
response.
|
void |
onByteChunkReceived(byte[] chunk,
long chunkLength,
long totalProcessed,
long totalLength)
Called when a chunk has been downloaded from the request.
|
void |
onByteChunkReceivedProcessed(long totalProcessed,
long totalLength)
Runs on the UI thread.
|
void |
onByteChunkSent(byte[] chunk,
long chunkLength,
long totalProcessed,
long totalLength)
Called when a chunk has been uploaded to the request.
|
void |
onByteChunkSentProcessed(long totalProcessed,
long totalLength)
Runs on the UI thread.
|
void |
onFailure()
Called when a response was not 2xx.
|
void |
onFinish()
Called when the streams have all finished, success or not.
|
void |
onReceiveStream(InputStream stream,
ClientTaskImpl client,
long totalLength)
Called when processing the response from a stream.
|
void |
onSend()
Called when the connection is first made
|
void |
onSuccess()
Processes the response from the stream.
|
public ConnectionInfo getConnectionInfo()
@WorkerThread public void onSend()
@WorkerThread public void onReceiveStream(InputStream stream, ClientTaskImpl client, long totalLength) throws SocketTimeoutException, Exception
onByteChunkReceived(byte[], long, long, long)stream - The response InputStreamclient - The client task. In order to call
onByteChunkReceivedProcessed(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 streamSocketTimeoutExceptionException@WorkerThread public void onByteChunkReceived(@Nullable byte[] chunk, long 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.@UiThread public void onByteChunkReceivedProcessed(long totalProcessed, long totalLength)
totalProcessed - The total processed sized of the requesttotalLength - The total length of the request@WorkerThread public void onByteChunkSent(@NonNull byte[] chunk, long chunkLength, long totalProcessed, long totalLength)
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.@UiThread public void onByteChunkSentProcessed(long totalProcessed, long totalLength)
totalProcessed - The total processed sized of the requesttotalLength - The total length of the request@WorkerThread public void beforeResponse()
onSuccess()@WorkerThread public abstract void generateContent()
onReceiveStream(java.io.InputStream, net.callumtaylor.asynchttp.obj.ClientTaskImpl, long) has finished@Nullable public abstract E getContent()
@WorkerThread public void onSuccess()
@WorkerThread public void onFailure()
@WorkerThread public void beforeFinish()
onFinish()@UiThread public void onFinish()