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); HttpContentChunkedInput 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(ChannelHandlerContext ctx)
Fetches a chunked data from the stream.
|
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
public HttpContent readChunk(ChannelHandlerContext ctx) throws Exception
ChunkedInput
ChunkedInput.isEndOfInput()
call must return true
.readChunk
in interface ChunkedInput<HttpContent>
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–2015 The Netty Project. All rights reserved.