Top Description Fields Constructors Methods
io.netty5.channel

public Class DefaultFileRegion

extends AbstractReferenceCounted
implements FileRegion
Class Inheritance
All Implemented Interfaces
io.netty5.channel.FileRegion, io.netty5.util.ReferenceCounted
Imports
io.netty5.util.AbstractReferenceCounted, .IllegalReferenceCountException, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.io.File, .IOException, .RandomAccessFile, java.nio.channels.FileChannel, .WritableByteChannel

Default FileRegion implementation which transfer data from a FileChannel or File. Be aware that the FileChannel will be automatically closed once refCnt() returns 0.

Field Summary

Modifier and TypeField and Description
private final long
private final File
f

private FileChannel
private static final InternalLogger
private final long
private long

Constructor Summary

AccessConstructor and Description
public
DefaultFileRegion(FileChannel
the FileChannel which should be transferred
file
,
long
the position from which the transfer should start
position
,
long
the number of bytes to transfer
count
)

Create a new instance

public
DefaultFileRegion(File
the File which should be transferred
f
,
long
the position from which the transfer should start
position
,
long
the number of bytes to transfer
count
)

Create a new instance using the given File.

Method Summary

Modifier and TypeMethod and Description
public long
count()

Implements io.netty5.channel.FileRegion.count.

Returns the number of bytes to transfer.
protected void
deallocate()

Implements abstract io.netty5.util.AbstractReferenceCounted.deallocate.

Called once refCnt() is equals 0.
public boolean
isOpen()

Returns true if the FileRegion has a open file-descriptor

public void
open()

Explicitly open the underlying file-descriptor if not done yet.

public long
position()

Implements io.netty5.channel.FileRegion.position.

Returns the offset in the file where the transfer began.
public FileRegion
public FileRegion
retain(int increment)

Overrides io.netty5.util.AbstractReferenceCounted.retain.

Implements io.netty5.channel.FileRegion.retain, io.netty5.util.ReferenceCounted.retain.

Increases the reference count by the specified increment.
public FileRegion
touch()

Overrides io.netty5.util.AbstractReferenceCounted.touch.

Implements io.netty5.channel.FileRegion.touch, io.netty5.util.ReferenceCounted.touch.

Records the current access location of this object for debugging purposes.
public FileRegion
touch(Object hint)

Implements io.netty5.channel.FileRegion.touch, io.netty5.util.ReferenceCounted.touch.

Records the current access location of this object with an additional arbitrary information for debugging purposes.
public long
transferred()

Implements io.netty5.channel.FileRegion.transferred.

Returns the bytes which was transferred already.
public long
transferTo(WritableByteChannel
the destination of the transfer
target
,
long
the relative offset of the file where the transfer begins from. For example, 0 will make the transfer start from position()th byte and count() - 1 will make the last byte of the region transferred.
position
)

Implements io.netty5.channel.FileRegion.transferTo.

Transfers the content of this file region to the specified channel.
pack-priv static void
validate(DefaultFileRegion region, long position)

Inherited from io.netty5.util.AbstractReferenceCounted:
refCntreleasereleasesetRefCnt

Field Detail

countback to summary
private final long count
fback to summary
private final File f
fileback to summary
private FileChannel file
loggerback to summary
private static final InternalLogger logger
positionback to summary
private final long position
transferredback to summary
private long transferred

Constructor Detail

DefaultFileRegionback to summary
public DefaultFileRegion(FileChannel file, long position, long count)

Create a new instance

Parameters
file:FileChannel

the FileChannel which should be transferred

position:long

the position from which the transfer should start

count:long

the number of bytes to transfer

DefaultFileRegionback to summary
public DefaultFileRegion(File f, long position, long count)

Create a new instance using the given File. The File will be opened lazily or explicitly via open().

Parameters
f:File

the File which should be transferred

position:long

the position from which the transfer should start

count:long

the number of bytes to transfer

Method Detail

countback to summary
public long count()

Implements io.netty5.channel.FileRegion.count.

Doc from io.netty5.channel.FileRegion.count.

Returns the number of bytes to transfer.

Annotations
@Override
deallocateback to summary
protected void deallocate()

Implements abstract io.netty5.util.AbstractReferenceCounted.deallocate.

Doc from io.netty5.util.AbstractReferenceCounted.deallocate.

Called once refCnt() is equals 0.

Annotations
@Override
isOpenback to summary
public boolean isOpen()

Returns true if the FileRegion has a open file-descriptor

openback to summary
public void open() throws IOException

Explicitly open the underlying file-descriptor if not done yet.

positionback to summary
public long position()

Implements io.netty5.channel.FileRegion.position.

Doc from io.netty5.channel.FileRegion.position.

Returns the offset in the file where the transfer began.

Annotations
@Override
retainback to summary
public FileRegion retain()

Overrides io.netty5.util.AbstractReferenceCounted.retain.

Implements io.netty5.channel.FileRegion.retain, io.netty5.util.ReferenceCounted.retain.

Doc from io.netty5.util.ReferenceCounted.retain.

Increases the reference count by 1.

Annotations
@Override
retainback to summary
public FileRegion retain(int increment)

Overrides io.netty5.util.AbstractReferenceCounted.retain.

Implements io.netty5.channel.FileRegion.retain, io.netty5.util.ReferenceCounted.retain.

Doc from io.netty5.util.ReferenceCounted.retain.

Increases the reference count by the specified increment.

Annotations
@Override
touchback to summary
public FileRegion touch()

Overrides io.netty5.util.AbstractReferenceCounted.touch.

Implements io.netty5.channel.FileRegion.touch, io.netty5.util.ReferenceCounted.touch.

Doc from io.netty5.util.ReferenceCounted.touch.

Records the current access location of this object for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you via ResourceLeakDetector. This method is a shortcut to touch(null).

Annotations
@Override
touchback to summary
public FileRegion touch(Object hint)

Implements io.netty5.channel.FileRegion.touch, io.netty5.util.ReferenceCounted.touch.

Doc from io.netty5.util.ReferenceCounted.touch.

Records the current access location of this object with an additional arbitrary information for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you via ResourceLeakDetector.

Annotations
@Override
transferredback to summary
public long transferred()

Implements io.netty5.channel.FileRegion.transferred.

Doc from io.netty5.channel.FileRegion.transferred.

Returns the bytes which was transferred already.

Annotations
@Override
transferToback to summary
public long transferTo(WritableByteChannel target, long position) throws IOException

Implements io.netty5.channel.FileRegion.transferTo.

Doc from io.netty5.channel.FileRegion.transferTo.

Transfers the content of this file region to the specified channel.

Parameters
target:WritableByteChannel

the destination of the transfer

position:long

the relative offset of the file where the transfer begins from. For example, 0 will make the transfer start from position()th byte and count() - 1 will make the last byte of the region transferred.

Annotations
@Override
validateback to summary
pack-priv static void validate(DefaultFileRegion region, long position) throws IOException