public class HttpChunkedInput extends java.lang.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); }
构造器和说明 |
---|
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.
|
限定符和类型 | 方法和说明 |
---|---|
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)
已过时。
|
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 java.lang.Exception
ChunkedInput
true
if and only if there is no data left in the stream
and the stream has reached at its end.isEndOfInput
在接口中 ChunkedInput<HttpContent>
java.lang.Exception
public void close() throws java.lang.Exception
ChunkedInput
close
在接口中 ChunkedInput<HttpContent>
java.lang.Exception
@Deprecated public HttpContent readChunk(ChannelHandlerContext ctx) throws java.lang.Exception
readChunk
在接口中 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.java.lang.Exception
public HttpContent readChunk(ByteBufAllocator allocator) throws java.lang.Exception
ChunkedInput
ChunkedInput.isEndOfInput()
call must return true
.readChunk
在接口中 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.java.lang.Exception
public long length()
ChunkedInput
length
在接口中 ChunkedInput<HttpContent>
public long progress()
ChunkedInput
progress
在接口中 ChunkedInput<HttpContent>