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
ChunkedInput
true
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>
Exception
public void close() throws Exception
ChunkedInput
close
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.Exception
public HttpContent readChunk(ByteBufAllocator allocator) throws Exception
ChunkedInput
ChunkedInput.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.Exception
public long length()
ChunkedInput
length
in interface ChunkedInput<HttpContent>
public long progress()
ChunkedInput
progress
in interface ChunkedInput<HttpContent>
Copyright © 2008–2024 The Netty Project. All rights reserved.