ChunkedInput that fetches data chunk by chunk for use with HTTP/2 Data Frames.
Each chunk from the input data will be wrapped within a Http2DataFrame. At the end of the input data,
Http2DataFrame#isEndStream() will be set to true and will be written.
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof Http2HeadersFrame) {
Http2HeadersFrame http2HeadersFrame = (Http2HeadersFrame) msg;
Http2HeadersFrame response = new DefaultHttp2HeadersFrame(new DefaultHttp2Headers().status("200"));
response.stream(http2HeadersFrame.stream());
ctx.write(response);
ChannelFuture sendFileFuture = ctx.writeAndFlush(new Http2DataChunkedInput(
new ChunkedFile(new File(("/home/meow/cats.mp4"))), http2HeadersFrame.stream()));
}
}
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private final ChunkedInput | |
| private final Http2FrameStream |
| Access | Constructor and Description |
|---|---|
| public | Http2DataChunkedInput(ChunkedInput<ByteBuf>
ChunkedInput containing data to writeHttp2FrameStream holding stream infoCreates a new instance using the specified input. |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Implements io. |
| public boolean | isEndOfInput()
Implements io. true if and only if there is no data left in the stream
and the stream has reached at its end.
|
| public long | |
| public long | progress()
Implements io. |
| public Http2DataFrame | readChunk(ChannelHandlerContext
The context which provides a ctx)ByteBufAllocator if buffer allocation is necessary.Implements io.
Deprecated
|
| public Http2DataFrame | readChunk(ByteBufAllocator
ByteBufAllocator if buffer allocation is necessary.Implements io. |
| endStreamSent | back to summary |
|---|---|
| private boolean endStreamSent | |
| input | back to summary |
|---|---|
| private final ChunkedInput<ByteBuf> input | |
| stream | back to summary |
|---|---|
| private final Http2FrameStream stream | |
| Http2DataChunkedInput | back to summary |
|---|---|
| public Http2DataChunkedInput(ChunkedInput<ByteBuf> input, Http2FrameStream stream) Creates a new instance using the specified input.
| |
| close | back to summary |
|---|---|
| public void close() throws Exception Implements io. Doc from io. Releases the resources associated with the input.
| |
| isEndOfInput | back to summary |
|---|---|
| public boolean isEndOfInput() throws Exception Implements io. Doc from io. Return
| |
| length | back to summary |
|---|---|
| public long length() Implements io. Doc from io. Returns the length of the input.
| |
| progress | back to summary |
|---|---|
| public long progress() Implements io. Doc from io. Returns current transfer progress.
| |
| readChunk | back to summary |
|---|---|
| public Http2DataFrame readChunk(ChannelHandlerContext ctx) throws Exception Implements io. Deprecated
| |
| readChunk | back to summary |
|---|---|
| public Http2DataFrame readChunk(ByteBufAllocator allocator) throws Exception Implements io. Doc from io. Fetches a chunked data from the stream. Once this method returns the last chunk
and thus the stream has reached at its end, any subsequent
| |