- java.lang.Object
-
- io.netty5.util.AbstractReferenceCounted
-
- io.netty5.channel.DefaultFileRegion
-
- All Implemented Interfaces:
FileRegion
,ReferenceCounted
public class DefaultFileRegion extends AbstractReferenceCounted implements FileRegion
DefaultFileRegion
implementation which transfer data from aFileChannel
orFile
. Be aware that theFileChannel
will be automatically closed onceAbstractReferenceCounted.refCnt()
returns0
.
-
-
Constructor Summary
Constructors Constructor Description DefaultFileRegion(File f, long position, long count)
Create a new instance using the givenFile
.DefaultFileRegion(FileChannel file, long position, long count)
Create a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description long
count()
Returns the number of bytes to transfer.protected void
deallocate()
Called onceAbstractReferenceCounted.refCnt()
is equals 0.boolean
isOpen()
Returnstrue
if theFileRegion
has a open file-descriptorvoid
open()
Explicitly open the underlying file-descriptor if not done yet.long
position()
Returns the offset in the file where the transfer began.FileRegion
retain()
Increases the reference count by1
.FileRegion
retain(int increment)
Increases the reference count by the specifiedincrement
.FileRegion
touch()
Records the current access location of this object for debugging purposes.FileRegion
touch(Object hint)
Records the current access location of this object with an additional arbitrary information for debugging purposes.long
transfered()
Deprecated.long
transferred()
Returns the bytes which was transferred already.long
transferTo(WritableByteChannel target, long position)
Transfers the content of this file region to the specified channel.-
Methods inherited from class io.netty5.util.AbstractReferenceCounted
refCnt, release, release, setRefCnt
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.util.ReferenceCounted
refCnt, release, release
-
-
-
-
Constructor Detail
-
DefaultFileRegion
public DefaultFileRegion(FileChannel file, long position, long count)
Create a new instance- Parameters:
file
- theFileChannel
which should be transferredposition
- the position from which the transfer should startcount
- the number of bytes to transfer
-
DefaultFileRegion
public DefaultFileRegion(File f, long position, long count)
Create a new instance using the givenFile
. TheFile
will be opened lazily or explicitly viaopen()
.- Parameters:
f
- theFile
which should be transferredposition
- the position from which the transfer should startcount
- the number of bytes to transfer
-
-
Method Detail
-
isOpen
public boolean isOpen()
Returnstrue
if theFileRegion
has a open file-descriptor
-
open
public void open() throws IOException
Explicitly open the underlying file-descriptor if not done yet.- Throws:
IOException
-
position
public long position()
Description copied from interface:FileRegion
Returns the offset in the file where the transfer began.- Specified by:
position
in interfaceFileRegion
-
count
public long count()
Description copied from interface:FileRegion
Returns the number of bytes to transfer.- Specified by:
count
in interfaceFileRegion
-
transfered
@Deprecated public long transfered()
Deprecated.Description copied from interface:FileRegion
Returns the bytes which was transferred already.- Specified by:
transfered
in interfaceFileRegion
-
transferred
public long transferred()
Description copied from interface:FileRegion
Returns the bytes which was transferred already.- Specified by:
transferred
in interfaceFileRegion
-
transferTo
public long transferTo(WritableByteChannel target, long position) throws IOException
Description copied from interface:FileRegion
Transfers the content of this file region to the specified channel.- Specified by:
transferTo
in interfaceFileRegion
- Parameters:
target
- the destination of the transferposition
- the relative offset of the file where the transfer begins from. For example, 0 will make the transfer start fromFileRegion.position()
th byte andFileRegion.count()
- 1 will make the last byte of the region transferred.- Throws:
IOException
-
deallocate
protected void deallocate()
Description copied from class:AbstractReferenceCounted
Called onceAbstractReferenceCounted.refCnt()
is equals 0.- Specified by:
deallocate
in classAbstractReferenceCounted
-
retain
public FileRegion retain()
Description copied from interface:ReferenceCounted
Increases the reference count by1
.- Specified by:
retain
in interfaceFileRegion
- Specified by:
retain
in interfaceReferenceCounted
- Overrides:
retain
in classAbstractReferenceCounted
-
retain
public FileRegion retain(int increment)
Description copied from interface:ReferenceCounted
Increases the reference count by the specifiedincrement
.- Specified by:
retain
in interfaceFileRegion
- Specified by:
retain
in interfaceReferenceCounted
- Overrides:
retain
in classAbstractReferenceCounted
-
touch
public FileRegion touch()
Description copied from interface:ReferenceCounted
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 viaResourceLeakDetector
. This method is a shortcut totouch(null)
.- Specified by:
touch
in interfaceFileRegion
- Specified by:
touch
in interfaceReferenceCounted
- Overrides:
touch
in classAbstractReferenceCounted
-
touch
public FileRegion touch(Object hint)
Description copied from interface:ReferenceCounted
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 viaResourceLeakDetector
.- Specified by:
touch
in interfaceFileRegion
- Specified by:
touch
in interfaceReferenceCounted
-
-