public class HttpChunkedInput extends Object implements ChunkedInput<HttpContent>
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);
 }
 | Constructor and Description | 
|---|
HttpChunkedInput(ChunkedInput<ByteBuf> input)
Creates a new instance using the specified input. 
 | 
HttpChunkedInput(ChunkedInput<ByteBuf> input,
                LastHttpContent lastHttpContent)
Creates a new instance using the specified input. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
void | 
close()
Releases the resources associated with the input. 
 | 
boolean | 
isEndOfInput()
Return  
true if and only if there is no data left in the stream
 and the stream has reached at its end. | 
long | 
length()
Returns the length of the input. 
 | 
long | 
progress()
Returns current transfer progress. 
 | 
HttpContent | 
readChunk(ByteBufAllocator allocator)
Fetches a chunked data from the stream. 
 | 
HttpContent | 
readChunk(ChannelHandlerContext ctx)
Deprecated.  
 | 
public HttpChunkedInput(ChunkedInput<ByteBuf> input)
input - ChunkedInput containing data to writepublic HttpChunkedInput(ChunkedInput<ByteBuf> input, LastHttpContent lastHttpContent)
lastHttpContent will be written as the terminating
 chunk.input - ChunkedInput containing data to writelastHttpContent - LastHttpContent that will be written as the terminating chunk. Use this for
            training headers.public boolean isEndOfInput()
                     throws Exception
ChunkedInputtrue if and only if there is no data left in the stream
 and the stream has reached at its end.isEndOfInput in interface ChunkedInput<HttpContent>Exceptionpublic void close()
           throws Exception
ChunkedInputclose in interface ChunkedInput<HttpContent>Exception@Deprecated public HttpContent readChunk(ChannelHandlerContext ctx) throws Exception
readChunk in interface ChunkedInput<HttpContent>ctx - The context which provides a ByteBufAllocator if buffer allocation is necessary.null if there is no data left in the stream.
         Please note that null does not necessarily mean that the
         stream has reached at its end.  In a slow stream, the next chunk
         might be unavailable just momentarily.Exceptionpublic HttpContent readChunk(ByteBufAllocator allocator) throws Exception
ChunkedInputChunkedInput.isEndOfInput()
 call must return true.readChunk in interface ChunkedInput<HttpContent>allocator - ByteBufAllocator if buffer allocation is necessary.null if there is no data left in the stream.
         Please note that null does not necessarily mean that the
         stream has reached at its end.  In a slow stream, the next chunk
         might be unavailable just momentarily.Exceptionpublic long length()
ChunkedInputlength in interface ChunkedInput<HttpContent>public long progress()
ChunkedInputprogress in interface ChunkedInput<HttpContent>Copyright © 2008–2025 The Netty Project. All rights reserved.