Class HttpChunkedInput

  • All Implemented Interfaces:
    ChunkedInput<HttpContent>

    public class HttpChunkedInput
    extends Object
    implements ChunkedInput<HttpContent>
    A 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"));
         ChannelFuture sendFileFuture = ctx.write(httpChunkWriter);
     }
     
    • Constructor Detail

      • HttpChunkedInput

        public HttpChunkedInput​(ChunkedInput<ByteBuf> input)
        Creates a new instance using the specified input.
        Parameters:
        input - ChunkedInput containing data to write
      • HttpChunkedInput

        public HttpChunkedInput​(ChunkedInput<ByteBuf> input,
                                LastHttpContent lastHttpContent)
        Creates a new instance using the specified input. lastHttpContent will be written as the terminating chunk.
        Parameters:
        input - ChunkedInput containing data to write
        lastHttpContent - LastHttpContent that will be written as the terminating chunk. Use this for training headers.