Package io.netty.handler.codec.http
Class HttpChunkedInput
java.lang.Object
io.netty.handler.codec.http.HttpChunkedInput
- All Implemented Interfaces:
io.netty.handler.stream.ChunkedInput<HttpContent>
public class HttpChunkedInput
extends Object
implements io.netty.handler.stream.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);
HttpChunkedInput httpChunkWriter = new HttpChunkedInput(
new ChunkedFile("/tmp/myfile.txt"));
ChannelFuture sendFileFuture = ctx.write(httpChunkWriter);
}
-
Constructor Summary
ConstructorsConstructorDescriptionHttpChunkedInput(io.netty.handler.stream.ChunkedInput<io.netty.buffer.ByteBuf> input) Creates a new instance using the specified input.HttpChunkedInput(io.netty.handler.stream.ChunkedInput<io.netty.buffer.ByteBuf> input, LastHttpContent lastHttpContent) Creates a new instance using the specified input. -
Method Summary
-
Constructor Details
-
HttpChunkedInput
public HttpChunkedInput(io.netty.handler.stream.ChunkedInput<io.netty.buffer.ByteBuf> input) Creates a new instance using the specified input.- Parameters:
input-ChunkedInputcontaining data to write
-
HttpChunkedInput
public HttpChunkedInput(io.netty.handler.stream.ChunkedInput<io.netty.buffer.ByteBuf> input, LastHttpContent lastHttpContent) Creates a new instance using the specified input.lastHttpContentwill be written as the terminating chunk.- Parameters:
input-ChunkedInputcontaining data to writelastHttpContent-LastHttpContentthat will be written as the terminating chunk. Use this for training headers.
-
-
Method Details
-
isEndOfInput
- Specified by:
isEndOfInputin interfaceio.netty.handler.stream.ChunkedInput<HttpContent>- Throws:
Exception
-
close
- Specified by:
closein interfaceio.netty.handler.stream.ChunkedInput<HttpContent>- Throws:
Exception
-
readChunk
@Deprecated public HttpContent readChunk(io.netty.channel.ChannelHandlerContext ctx) throws Exception Deprecated.- Specified by:
readChunkin interfaceio.netty.handler.stream.ChunkedInput<HttpContent>- Throws:
Exception
-
readChunk
- Specified by:
readChunkin interfaceio.netty.handler.stream.ChunkedInput<HttpContent>- Throws:
Exception
-
length
public long length()- Specified by:
lengthin interfaceio.netty.handler.stream.ChunkedInput<HttpContent>
-
progress
public long progress()- Specified by:
progressin interfaceio.netty.handler.stream.ChunkedInput<HttpContent>
-