Top Description Fields Constructors Methods
io.netty.handler.codec.http

public Class HttpChunkedInput

extends Object
implements ChunkedInput<HttpContent>
Class Inheritance
All Implemented Interfaces
io.netty.handler.stream.ChunkedInput
Imports
io.netty.buffer.ByteBuf, .ByteBufAllocator, io.netty.channel.ChannelHandlerContext, io.netty.handler.stream.ChunkedInput

A 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);
}

Field Summary

Modifier and TypeField and Description
private final ChunkedInput<ByteBuf>
private final LastHttpContent
private boolean

Constructor Summary

AccessConstructor and Description
public
HttpChunkedInput(ChunkedInput<ByteBuf>
ChunkedInput containing data to write
input
)

Creates a new instance using the specified input.

public
HttpChunkedInput(ChunkedInput<ByteBuf>
ChunkedInput containing data to write
input
,
LastHttpContent
LastHttpContent that will be written as the terminating chunk. Use this for training headers.
lastHttpContent
)

Creates a new instance using the specified input.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements io.netty.handler.stream.ChunkedInput.close.

Releases the resources associated with the input.
public boolean
isEndOfInput()

Implements io.netty.handler.stream.ChunkedInput.isEndOfInput.

Return true if and only if there is no data left in the stream and the stream has reached at its end.
public long
length()

Implements io.netty.handler.stream.ChunkedInput.length.

Returns the length of the input.
public long
progress()

Implements io.netty.handler.stream.ChunkedInput.progress.

Returns current transfer progress.
public HttpContent
readChunk(ChannelHandlerContext
The context which provides a ByteBufAllocator if buffer allocation is necessary.
ctx
)

Implements io.netty.handler.stream.ChunkedInput.readChunk.

Deprecated
public HttpContent
readChunk(ByteBufAllocator
ByteBufAllocator if buffer allocation is necessary.
allocator
)

Implements io.netty.handler.stream.ChunkedInput.readChunk.

Fetches a chunked data from the stream.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

inputback to summary
private final ChunkedInput<ByteBuf> input
lastHttpContentback to summary
private final LastHttpContent lastHttpContent
sentLastChunkback to summary
private boolean sentLastChunk

Constructor Detail

HttpChunkedInputback to summary
public HttpChunkedInput(ChunkedInput<ByteBuf> input)

Creates a new instance using the specified input.

Parameters
input:ChunkedInput<ByteBuf>

ChunkedInput containing data to write

HttpChunkedInputback to summary
public HttpChunkedInput(ChunkedInput<ByteBuf> input, LastHttpContent lastHttpContent)

Creates a new instance using the specified input. lastHttpContent will be written as the terminating chunk.

Parameters
input:ChunkedInput<ByteBuf>

ChunkedInput containing data to write

lastHttpContent:LastHttpContent

LastHttpContent that will be written as the terminating chunk. Use this for training headers.

Method Detail

closeback to summary
public void close() throws Exception

Implements io.netty.handler.stream.ChunkedInput.close.

Doc from io.netty.handler.stream.ChunkedInput.close.

Releases the resources associated with the input.

Annotations
@Override
isEndOfInputback to summary
public boolean isEndOfInput() throws Exception

Implements io.netty.handler.stream.ChunkedInput.isEndOfInput.

Doc from io.netty.handler.stream.ChunkedInput.isEndOfInput.

Return true if and only if there is no data left in the stream and the stream has reached at its end.

Annotations
@Override
lengthback to summary
public long length()

Implements io.netty.handler.stream.ChunkedInput.length.

Doc from io.netty.handler.stream.ChunkedInput.length.

Returns the length of the input.

Returns:long

the length of the input if the length of the input is known. a negative value if the length of the input is unknown.

Annotations
@Override
progressback to summary
public long progress()

Implements io.netty.handler.stream.ChunkedInput.progress.

Doc from io.netty.handler.stream.ChunkedInput.progress.

Returns current transfer progress.

Annotations
@Override
readChunkback to summary
public HttpContent readChunk(ChannelHandlerContext ctx) throws Exception

Implements io.netty.handler.stream.ChunkedInput.readChunk.

Deprecated

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.handler.stream.ChunkedInput.readChunk.

The context which provides a ByteBufAllocator if buffer allocation is necessary.

Returns:HttpContent

Doc from io.netty.handler.stream.ChunkedInput.readChunk.

the fetched chunk. 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.

Annotations
@Deprecated
@Override
readChunkback to summary
public HttpContent readChunk(ByteBufAllocator allocator) throws Exception

Implements io.netty.handler.stream.ChunkedInput.readChunk.

Doc from io.netty.handler.stream.ChunkedInput.readChunk.

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 isEndOfInput() call must return true.

Parameters
allocator:ByteBufAllocator

ByteBufAllocator if buffer allocation is necessary.

Returns:HttpContent

the fetched chunk. 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.

Annotations
@Override