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);
HttpChunkedInput httpChunkWriter = new HttpChunkedInput(
new ChunkedFile("/tmp/myfile.txt"));
ChannelFuture 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<ByteBuf>
ChunkedInput containing data to writeCreates a new instance using the specified input. |
| public | HttpChunkedInput(ChunkedInput<ByteBuf>
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 io. |
| 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(ChannelHandlerContext
The context which provides a ctx)ByteBufAllocator if buffer allocation is necessary.Implements io.
Deprecated
|
| public HttpContent | readChunk(ByteBufAllocator
ByteBufAllocator if buffer allocation is necessary.Implements io. |
| input | back to summary |
|---|---|
| private final ChunkedInput<ByteBuf> input | |
| lastHttpContent | back to summary |
|---|---|
| private final LastHttpContent lastHttpContent | |
| sentLastChunk | back to summary |
|---|---|
| private boolean sentLastChunk | |
| HttpChunkedInput | back to summary |
|---|---|
| public HttpChunkedInput(ChunkedInput<ByteBuf> input) Creates a new instance using the specified input.
| |
| HttpChunkedInput | back to summary |
|---|---|
| public HttpChunkedInput(ChunkedInput<ByteBuf> input, LastHttpContent lastHttpContent) Creates a new instance using the specified input.
| |
| close | back to summary |
|---|---|
| public void close() throws Exception Implements io. Doc from io. Releases the resources associated with the input.
| |
| 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 readChunk(ChannelHandlerContext ctx) throws Exception Implements io. Deprecated
| |
| readChunk | back to summary |
|---|---|
| public HttpContent readChunk(ByteBufAllocator allocator) throws Exception 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
| |