Top Description Fields Constructors Methods
io.netty.handler.stream

public Class ChunkedFile

extends Object
implements ChunkedInput<ByteBuf>
Class Inheritance
All Implemented Interfaces
io.netty.handler.stream.ChunkedInput
Imports
io.netty.buffer.ByteBuf, .ByteBufAllocator, io.netty.channel.ChannelHandlerContext, .FileRegion, io.netty.util.internal.ObjectUtil, java.io.File, .IOException, .RandomAccessFile

A ChunkedInput that fetches data from a file chunk by chunk.

If your operating system supports zero-copy file transfer such as sendfile(), you might want to use FileRegion instead.

Field Summary

Modifier and TypeField and Description
private final int
private final long
private final RandomAccessFile
private long
private final long

Constructor Summary

AccessConstructor and Description
public
ChunkedFile(File file)

Creates a new instance that fetches data from the specified file.

public
ChunkedFile(File file, int
the number of bytes to fetch on each readChunk(ChannelHandlerContext) call
chunkSize
)

Creates a new instance that fetches data from the specified file.

public
ChunkedFile(RandomAccessFile file)

Creates a new instance that fetches data from the specified file.

public
ChunkedFile(RandomAccessFile file, int
the number of bytes to fetch on each readChunk(ChannelHandlerContext) call
chunkSize
)

Creates a new instance that fetches data from the specified file.

public
ChunkedFile(RandomAccessFile file, long
the offset of the file where the transfer begins
offset
,
long
the number of bytes to transfer
length
,
int
the number of bytes to fetch on each readChunk(ChannelHandlerContext) call
chunkSize
)

Creates a new instance that fetches data from the specified file.

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 long
currentOffset()

Returns the offset in the file where the transfer is happening currently.

public long
endOffset()

Returns the offset in the file where the transfer will end.

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 ByteBuf
readChunk(ChannelHandlerContext
The context which provides a ByteBufAllocator if buffer allocation is necessary.
ctx
)

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

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

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

Fetches a chunked data from the stream.
public long
startOffset()

Returns the offset in the file where the transfer began.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

chunkSizeback to summary
private final int chunkSize
endOffsetback to summary
private final long endOffset
fileback to summary
private final RandomAccessFile file
offsetback to summary
private long offset
startOffsetback to summary
private final long startOffset

Constructor Detail

ChunkedFileback to summary
public ChunkedFile(File file) throws IOException

Creates a new instance that fetches data from the specified file.

ChunkedFileback to summary
public ChunkedFile(File file, int chunkSize) throws IOException

Creates a new instance that fetches data from the specified file.

Parameters
chunkSize:int

the number of bytes to fetch on each readChunk(ChannelHandlerContext) call

ChunkedFileback to summary
public ChunkedFile(RandomAccessFile file) throws IOException

Creates a new instance that fetches data from the specified file.

ChunkedFileback to summary
public ChunkedFile(RandomAccessFile file, int chunkSize) throws IOException

Creates a new instance that fetches data from the specified file.

Parameters
chunkSize:int

the number of bytes to fetch on each readChunk(ChannelHandlerContext) call

ChunkedFileback to summary
public ChunkedFile(RandomAccessFile file, long offset, long length, int chunkSize) throws IOException

Creates a new instance that fetches data from the specified file.

Parameters
offset:long

the offset of the file where the transfer begins

length:long

the number of bytes to transfer

chunkSize:int

the number of bytes to fetch on each readChunk(ChannelHandlerContext) call

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
currentOffsetback to summary
public long currentOffset()

Returns the offset in the file where the transfer is happening currently.

endOffsetback to summary
public long endOffset()

Returns the offset in the file where the transfer will end.

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 ByteBuf 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:ByteBuf

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 ByteBuf 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:ByteBuf

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
startOffsetback to summary
public long startOffset()

Returns the offset in the file where the transfer began.