Class ZeroCopyConsumer<T>
java.lang.Object
org.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>
org.apache.http.nio.client.methods.ZeroCopyConsumer<T>
- All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.http.concurrent.Cancellable, org.apache.http.nio.protocol.HttpAsyncResponseConsumer<T>
public abstract class ZeroCopyConsumer<T>
extends org.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>
HttpAsyncResponseConsumer implementation that
streams content entity enclosed in an HTTP response directly into a file
without an intermediate in-memory buffer.
This consumer can be useful for file downloads.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RandomAccessFileprivate org.apache.http.Headerprivate org.apache.http.entity.ContentTypeprivate final Fileprivate FileChannelprivate longprivate org.apache.http.HttpResponse -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected TbuildResult(org.apache.http.protocol.HttpContext context) protected voidonContentReceived(org.apache.http.nio.ContentDecoder decoder, org.apache.http.nio.IOControl ioctrl) protected voidonEntityEnclosed(org.apache.http.HttpEntity entity, org.apache.http.entity.ContentType contentType) protected voidonResponseReceived(org.apache.http.HttpResponse response) protected abstract Tprocess(org.apache.http.HttpResponse response, File file, org.apache.http.entity.ContentType contentType) Invoked to process received file.protected voidMethods inherited from class org.apache.http.nio.protocol.AbstractAsyncResponseConsumer
cancel, close, consumeContent, failed, getContentType, getException, getResult, isDone, onClose, responseCompleted, responseReceived
-
Field Details
-
file
-
accessfile
-
response
private org.apache.http.HttpResponse response -
contentType
private org.apache.http.entity.ContentType contentType -
contentEncoding
private org.apache.http.Header contentEncoding -
fileChannel
-
idx
private long idx
-
-
Constructor Details
-
ZeroCopyConsumer
- Throws:
FileNotFoundException
-
-
Method Details
-
onResponseReceived
protected void onResponseReceived(org.apache.http.HttpResponse response) - Specified by:
onResponseReceivedin classorg.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>
-
onEntityEnclosed
protected void onEntityEnclosed(org.apache.http.HttpEntity entity, org.apache.http.entity.ContentType contentType) throws IOException - Specified by:
onEntityEnclosedin classorg.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>- Throws:
IOException
-
onContentReceived
protected void onContentReceived(org.apache.http.nio.ContentDecoder decoder, org.apache.http.nio.IOControl ioctrl) throws IOException - Specified by:
onContentReceivedin classorg.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>- Throws:
IOException
-
process
protected abstract T process(org.apache.http.HttpResponse response, File file, org.apache.http.entity.ContentType contentType) throws Exception Invoked to process received file.- Parameters:
response- original response head.file- file containing response content.contentType- the cotnent type.- Returns:
- result of the response processing
- Throws:
Exception
-
buildResult
-
releaseResources
protected void releaseResources()- Specified by:
releaseResourcesin classorg.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>
-