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.
| Modifier and Type | Field and Description |
|---|---|
private java.io.RandomAccessFile |
accessfile |
private org.apache.http.Header |
contentEncoding |
private org.apache.http.entity.ContentType |
contentType |
private java.io.File |
file |
private java.nio.channels.FileChannel |
fileChannel |
private long |
idx |
private org.apache.http.HttpResponse |
response |
| Constructor and Description |
|---|
ZeroCopyConsumer(java.io.File file) |
| Modifier and Type | Method and Description |
|---|---|
protected T |
buildResult(org.apache.http.protocol.HttpContext context) |
protected void |
onContentReceived(org.apache.http.nio.ContentDecoder decoder,
org.apache.http.nio.IOControl ioctrl) |
protected void |
onEntityEnclosed(org.apache.http.HttpEntity entity,
org.apache.http.entity.ContentType contentType) |
protected void |
onResponseReceived(org.apache.http.HttpResponse response) |
protected abstract T |
process(org.apache.http.HttpResponse response,
java.io.File file,
org.apache.http.entity.ContentType contentType)
Invoked to process received file.
|
protected void |
releaseResources() |
private final java.io.File file
private final java.io.RandomAccessFile accessfile
private org.apache.http.HttpResponse response
private org.apache.http.entity.ContentType contentType
private org.apache.http.Header contentEncoding
private java.nio.channels.FileChannel fileChannel
private long idx
public ZeroCopyConsumer(java.io.File file)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionprotected void onResponseReceived(org.apache.http.HttpResponse response)
onResponseReceived in class org.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>protected void onEntityEnclosed(org.apache.http.HttpEntity entity,
org.apache.http.entity.ContentType contentType)
throws java.io.IOException
onEntityEnclosed in class org.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>java.io.IOExceptionprotected void onContentReceived(org.apache.http.nio.ContentDecoder decoder,
org.apache.http.nio.IOControl ioctrl)
throws java.io.IOException
onContentReceived in class org.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>java.io.IOExceptionprotected abstract T process(org.apache.http.HttpResponse response, java.io.File file, org.apache.http.entity.ContentType contentType) throws java.lang.Exception
response - original response head.file - file containing response content.contentType - the cotnent type.java.lang.Exceptionprotected T buildResult(org.apache.http.protocol.HttpContext context) throws java.lang.Exception
buildResult in class org.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>java.lang.Exceptionprotected void releaseResources()
releaseResources in class org.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>