Package com.ning.http.client.resumable
Class ResumableAsyncHandler<T>
java.lang.Object
com.ning.http.client.resumable.ResumableAsyncHandler<T>
- All Implemented Interfaces:
AsyncHandler<T>
An
AsyncHandler which support resumable download, e.g when used with an ResumableIOExceptionFilter,
this handler can resume the download operation at the point it was before the interruption occured. This prevent having to
download the entire file again. It's the responsibility of the TransferListener
to track how many bytes has been transferred and to properly adjust the file's write position.
In case of a JVM crash/shutdown, you can create an instance of this class and pass the last valid bytes position.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn interface to implement in order to manage the way the incomplete file management are handled.Nested classes/interfaces inherited from interface com.ning.http.client.AsyncHandler
AsyncHandler.STATE -
Constructor Summary
ConstructorsConstructorDescriptionResumableAsyncHandler(boolean accumulateBody) ResumableAsyncHandler(long byteTransferred) ResumableAsyncHandler(long byteTransferred, AsyncHandler<T> decoratedAsyncHandler) ResumableAsyncHandler(AsyncHandler<T> decoratedAsyncHandler) ResumableAsyncHandler(ResumableAsyncHandler.ResumableProcessor resumableProcessor) ResumableAsyncHandler(ResumableAsyncHandler.ResumableProcessor resumableProcessor, boolean accumulateBody) -
Method Summary
Modifier and TypeMethodDescriptionadjustRequestRange(Request request) Invoke this API if you want to set the Range header on yourRequestbased on the last valid bytes position.onBodyPartReceived(HttpResponseBodyPart bodyPart) Invoked as soon as some response body part are received.Invoked once the HTTP response processing is finished.onHeadersReceived(HttpResponseHeaders headers) Invoked as soon as the HTTP headers has been received.onStatusReceived(HttpResponseStatus status) Invoked as soon as the HTTP status line has been receivedvoidInvoked when an unexpected exception occurs during the processing of the response.setResumableListener(ResumableListener resumableListener) Set aResumableListener
-
Constructor Details
-
ResumableAsyncHandler
public ResumableAsyncHandler(long byteTransferred) -
ResumableAsyncHandler
public ResumableAsyncHandler(boolean accumulateBody) -
ResumableAsyncHandler
public ResumableAsyncHandler() -
ResumableAsyncHandler
-
ResumableAsyncHandler
-
ResumableAsyncHandler
-
ResumableAsyncHandler
public ResumableAsyncHandler(ResumableAsyncHandler.ResumableProcessor resumableProcessor, boolean accumulateBody)
-
-
Method Details
-
onStatusReceived
Description copied from interface:AsyncHandlerInvoked as soon as the HTTP status line has been received- Specified by:
onStatusReceivedin interfaceAsyncHandler<T>- Parameters:
status- the status code and test of the response- Returns:
- a
AsyncHandler.STATEtelling to CONTINUE or ABORT the current processing. - Throws:
Exception- if something wrong happens
-
onThrowable
Description copied from interface:AsyncHandlerInvoked when an unexpected exception occurs during the processing of the response. The exception may have been produced by implementation of onXXXReceived method invocation.- Specified by:
onThrowablein interfaceAsyncHandler<T>- Parameters:
t- aThrowable
-
onBodyPartReceived
Description copied from interface:AsyncHandlerInvoked as soon as some response body part are received. Could be invoked many times.- Specified by:
onBodyPartReceivedin interfaceAsyncHandler<T>- Parameters:
bodyPart- response's body part.- Returns:
- a
AsyncHandler.STATEtelling to CONTINUE or ABORT the current processing. - Throws:
Exception- if something wrong happens
-
onCompleted
Description copied from interface:AsyncHandlerInvoked once the HTTP response processing is finished. Gets always invoked as last callback method.- Specified by:
onCompletedin interfaceAsyncHandler<T>- Returns:
- T Value that will be returned by the associated
Future - Throws:
Exception- if something wrong happens
-
onHeadersReceived
Description copied from interface:AsyncHandlerInvoked as soon as the HTTP headers has been received. Can potentially be invoked more than once if a broken server sent trailing headers.- Specified by:
onHeadersReceivedin interfaceAsyncHandler<T>- Parameters:
headers- the HTTP headers.- Returns:
- a
AsyncHandler.STATEtelling to CONTINUE or ABORT the current processing. - Throws:
Exception- if something wrong happens
-
adjustRequestRange
Invoke this API if you want to set the Range header on yourRequestbased on the last valid bytes position. -
setResumableListener
Set aResumableListener- Parameters:
resumableListener- aResumableListener- Returns:
- this
-