public class

TransferCompletionHandler

extends AsyncCompletionHandlerBase
java.lang.Object
   ↳ com.ning.http.client.AsyncCompletionHandler<T>
     ↳ com.ning.http.client.AsyncCompletionHandlerBase
       ↳ com.ning.http.client.listener.TransferCompletionHandler

Class Overview

A AsyncHandler that can be used to notify a set of TransferListener

 AsyncHttpClient client = new AsyncHttpClient();
 TransferCompletionHandler tl = new TransferCompletionHandler();
 tl.addTransferListener(new TransferListener() {
 

public void onRequestHeadersSent(FluentCaseInsensitiveStringsMap headers) { }

public void onResponseHeadersReceived(FluentCaseInsensitiveStringsMap headers) { }

public void onBytesReceived(ByteBuffer buffer) { }

public void onBytesSent(ByteBuffer buffer) { }

public void onRequestResponseCompleted() { }

public void onThrowable(Throwable t) { } });

Response response = httpClient.prepareGet("http://...").execute(tl).get();

Summary

Nested Classes
class TransferCompletionHandler.TransferAdapter  
Public Constructors
TransferCompletionHandler()
Create a TransferCompletionHandler that will not accumulate bytes.
TransferCompletionHandler(boolean accumulateResponseBytes)
Create a TransferCompletionHandler that can or cannot accumulate bytes and make it available when getResponseBody() get called.
Public Methods
TransferCompletionHandler addTransferListener(TransferListener t)
AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart content)
Invoked as soon as some response body part are received.
Response onCompleted(Response response)
Invoked once the HTTP response processing is finished.
AsyncHandler.STATE onContentWriteCompleted()
Invoked when the content (a java.io.File, String or java.io.FileInputStream has been fully written on the I/O socket.
AsyncHandler.STATE onContentWriteProgress(long amount, long current, long total)
Invoked when the I/O operation associated with the Request body as been progressed.
AsyncHandler.STATE onHeaderWriteCompleted()
Invoked when the content (a java.io.File, String or java.io.FileInputStream has been fully written on the I/O socket.
AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers)
Invoked as soon as the HTTP headers has been received.
void onThrowable(Throwable t)
Invoked when an unexpected exception occurs during the processing of the response.
TransferCompletionHandler removeTransferListener(TransferListener t)
void transferAdapter(TransferCompletionHandler.TransferAdapter transferAdapter)
Associate a TransferCompletionHandler.TransferAdapter with this listener.
[Expand]
Inherited Methods
From class com.ning.http.client.AsyncCompletionHandlerBase
From class com.ning.http.client.AsyncCompletionHandler
From class java.lang.Object
From interface com.ning.http.client.AsyncHandler
From interface com.ning.http.client.ProgressAsyncHandler

Public Constructors

public TransferCompletionHandler ()

Create a TransferCompletionHandler that will not accumulate bytes. The resulting getResponseBody(), getResponseBodyAsStream() and getResponseBodyExcerpt(int) will throw an IllegalStateException if called.

public TransferCompletionHandler (boolean accumulateResponseBytes)

Create a TransferCompletionHandler that can or cannot accumulate bytes and make it available when getResponseBody() get called. The default is false.

Parameters
accumulateResponseBytes true to accumulates bytes in memory.

Public Methods

public TransferCompletionHandler addTransferListener (TransferListener t)

Parameters
t a TransferListener
Returns
  • this

public AsyncHandler.STATE onBodyPartReceived (HttpResponseBodyPart content)

Invoked as soon as some response body part are received. Could be invoked many times.

Parameters
content response's body part.
Returns
Throws
Exception

public Response onCompleted (Response response)

Invoked once the HTTP response processing is finished.

Gets always invoked as last callback method.

Parameters
response The Response
Returns
  • T Value that will be returned by the associated java.util.concurrent.Future
Throws
Exception

public AsyncHandler.STATE onContentWriteCompleted ()

Invoked when the content (a java.io.File, String or java.io.FileInputStream has been fully written on the I/O socket.

Returns

public AsyncHandler.STATE onContentWriteProgress (long amount, long current, long total)

Invoked when the I/O operation associated with the Request body as been progressed.

Parameters
amount The amount of bytes to transfer.
current The amount of bytes transferred
total The total number of bytes transferred
Returns

public AsyncHandler.STATE onHeaderWriteCompleted ()

Invoked when the content (a java.io.File, String or java.io.FileInputStream has been fully written on the I/O socket.

Returns

public AsyncHandler.STATE onHeadersReceived (HttpResponseHeaders headers)

Invoked as soon as the HTTP headers has been received. Can potentially be invoked more than once if a broken server sent trailing headers.

Parameters
headers the HTTP headers.
Returns
Throws
Exception

public void onThrowable (Throwable t)

Invoked when an unexpected exception occurs during the processing of the response. The exception may have been produced by implementation of onXXXReceived method invocation.

Parameters
t a Throwable

public TransferCompletionHandler removeTransferListener (TransferListener t)

Parameters
t a TransferListener
Returns
  • this

public void transferAdapter (TransferCompletionHandler.TransferAdapter transferAdapter)

Associate a TransferCompletionHandler.TransferAdapter with this listener.

Parameters
transferAdapter TransferCompletionHandler.TransferAdapter