public class HttpChunkedInput extends Object implements io.netty.handler.stream.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);
HttpContentChunkedInput httpChunkWriter = new HttpChunkedInput(
new ChunkedFile("/tmp/myfile.txt"));
ChannelFuture sendFileFuture = ctx.write(httpChunkWriter);
}
| Constructor and Description |
|---|
HttpChunkedInput(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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
boolean |
isEndOfInput() |
long |
length() |
long |
progress() |
HttpContent |
readChunk(io.netty.buffer.ByteBufAllocator allocator) |
HttpContent |
readChunk(io.netty.channel.ChannelHandlerContext ctx)
Deprecated.
|
public HttpChunkedInput(io.netty.handler.stream.ChunkedInput<io.netty.buffer.ByteBuf> input)
input - ChunkedInput containing data to writepublic HttpChunkedInput(io.netty.handler.stream.ChunkedInput<io.netty.buffer.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
isEndOfInput in interface io.netty.handler.stream.ChunkedInput<HttpContent>Exceptionpublic void close()
throws Exception
close in interface io.netty.handler.stream.ChunkedInput<HttpContent>Exception@Deprecated public HttpContent readChunk(io.netty.channel.ChannelHandlerContext ctx) throws Exception
readChunk in interface io.netty.handler.stream.ChunkedInput<HttpContent>Exceptionpublic HttpContent readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception
readChunk in interface io.netty.handler.stream.ChunkedInput<HttpContent>Exceptionpublic long length()
length in interface io.netty.handler.stream.ChunkedInput<HttpContent>public long progress()
progress in interface io.netty.handler.stream.ChunkedInput<HttpContent>Copyright © 2008–2017 The Netty Project. All rights reserved.