ChunkedInput that fetches data chunk by chunk for use with HTTP chunked transfers.
Each chunk from the input data will be wrapped within a HttpContent. At the end of the input data,
LastHttpContent will be written.
Ensure that your HTTP response header contains Transfer-Encoding: chunked.
public void messageReceived(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
response.headers().set(TRANSFER_ENCODING, CHUNKED);
ctx.write(response);
HttpContentChunkedInput httpChunkWriter = new HttpChunkedInput(
new ChunkedFile("/tmp/myfile.txt"));
Future<Void> sendFileFuture = ctx.write(httpChunkWriter);
}
| Modifier and Type | Field and Description |
|---|---|
| private final ChunkedInput | |
| private final LastHttpContent | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | HttpChunkedInput(ChunkedInput<Buffer>
ChunkedInput containing data to writeLastHttpContent that will be written as the terminating chunk. Use this for
training headers.Creates a new instance using the specified input. |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Implements java. |
| public boolean | isEndOfInput()
Implements io. true if and only if there is no data left in the stream
and the stream has reached at its end.
|
| public long | |
| public long | progress()
Implements io. |
| public HttpContent | readChunk(BufferAllocator
BufferAllocator if buffer allocation is necessary.Implements io. |
| input | back to summary |
|---|---|
| private final ChunkedInput<Buffer> input | |
| lastHttpContent | back to summary |
|---|---|
| private final LastHttpContent<?> lastHttpContent | |
| sentLastChunk | back to summary |
|---|---|
| private boolean sentLastChunk | |
| HttpChunkedInput | back to summary |
|---|---|
| public HttpChunkedInput(ChunkedInput<Buffer> input, LastHttpContent<?> lastHttpContent) Creates a new instance using the specified input.
| |
| close | back to summary |
|---|---|
| public void close() throws Exception Implements java. Doc from java. Closes this resource, relinquishing any underlying resources.
This method is invoked automatically on objects managed by the
| |
| isEndOfInput | back to summary |
|---|---|
| public boolean isEndOfInput() throws Exception Implements io. Doc from io. Return
| |
| length | back to summary |
|---|---|
| public long length() Implements io. Doc from io. Returns the length of the input.
| |
| progress | back to summary |
|---|---|
| public long progress() Implements io. Doc from io. Returns current transfer progress.
| |
| readChunk | back to summary |
|---|---|
| public HttpContent Implements io. Doc from io. Fetches a chunked data from the stream. Once this method returns the last chunk
and thus the stream has reached at its end, any subsequent
| |