Package org.apache.http.nio.protocol
Class BasicAsyncResponseConsumer
- java.lang.Object
-
- org.apache.http.nio.protocol.AbstractAsyncResponseConsumer<HttpResponse>
-
- org.apache.http.nio.protocol.BasicAsyncResponseConsumer
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,Cancellable,HttpAsyncResponseConsumer<HttpResponse>
public class BasicAsyncResponseConsumer extends AbstractAsyncResponseConsumer<HttpResponse>
Basic implementation ofHttpAsyncResponseConsumer. Please note that this consumer buffers response content in memory and should be used for relatively small response messages.- Since:
- 4.2
-
-
Field Summary
Fields Modifier and Type Field Description private SimpleInputBufferbufprivate static intMAX_INITIAL_BUFFER_SIZEprivate HttpResponseresponse
-
Constructor Summary
Constructors Constructor Description BasicAsyncResponseConsumer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected HttpResponsebuildResult(HttpContext context)Invoked to generate a result object from the received HTTP response message.protected voidonContentReceived(ContentDecoder decoder, IOControl ioControl)Invoked to process a chunk of content from theContentDecoder.protected voidonEntityEnclosed(HttpEntity entity, ContentType contentType)Invoked if the response message encloses a content entity.protected voidonResponseReceived(HttpResponse response)Invoked when a HTTP response message is received.protected voidreleaseResources()Invoked to release all system resources currently allocated.-
Methods inherited from class org.apache.http.nio.protocol.AbstractAsyncResponseConsumer
cancel, close, consumeContent, failed, getContentType, getException, getResult, isDone, onClose, responseCompleted, responseReceived
-
-
-
-
Field Detail
-
MAX_INITIAL_BUFFER_SIZE
private static final int MAX_INITIAL_BUFFER_SIZE
- See Also:
- Constant Field Values
-
response
private volatile HttpResponse response
-
buf
private volatile SimpleInputBuffer buf
-
-
Method Detail
-
onResponseReceived
protected void onResponseReceived(HttpResponse response) throws java.io.IOException
Description copied from class:AbstractAsyncResponseConsumerInvoked when a HTTP response message is received. Please note that theAbstractAsyncResponseConsumer.onContentReceived(ContentDecoder, IOControl)method will be invoked only if the response messages has a content entity enclosed.- Specified by:
onResponseReceivedin classAbstractAsyncResponseConsumer<HttpResponse>- Parameters:
response- HTTP response message.- Throws:
java.io.IOException- in case of an I/O error
-
onEntityEnclosed
protected void onEntityEnclosed(HttpEntity entity, ContentType contentType) throws java.io.IOException
Description copied from class:AbstractAsyncResponseConsumerInvoked if the response message encloses a content entity.- Specified by:
onEntityEnclosedin classAbstractAsyncResponseConsumer<HttpResponse>- Parameters:
entity- HTTP entitycontentType- expected content type.- Throws:
java.io.IOException- in case of an I/O error
-
onContentReceived
protected void onContentReceived(ContentDecoder decoder, IOControl ioControl) throws java.io.IOException
Description copied from class:AbstractAsyncResponseConsumerInvoked to process a chunk of content from theContentDecoder. TheIOControlinterface can be used to suspend input events if the consumer is temporarily unable to consume more content.The consumer can use the
ContentDecoder.isCompleted()method to find out whether or not the message content has been fully consumed.- Specified by:
onContentReceivedin classAbstractAsyncResponseConsumer<HttpResponse>- Parameters:
decoder- content decoder.ioControl- I/O control of the underlying connection.- Throws:
java.io.IOException- in case of an I/O error
-
releaseResources
protected void releaseResources()
Description copied from class:AbstractAsyncResponseConsumerInvoked to release all system resources currently allocated.- Specified by:
releaseResourcesin classAbstractAsyncResponseConsumer<HttpResponse>
-
buildResult
protected HttpResponse buildResult(HttpContext context)
Description copied from class:AbstractAsyncResponseConsumerInvoked to generate a result object from the received HTTP response message.- Specified by:
buildResultin classAbstractAsyncResponseConsumer<HttpResponse>- Parameters:
context- HTTP context.- Returns:
- result of the response processing.
-
-