Package io.netty.channel
Class DefaultFileRegion
java.lang.Object
io.netty.util.AbstractReferenceCounted
io.netty.channel.DefaultFileRegion
- All Implemented Interfaces:
FileRegion
,ReferenceCounted
Default
FileRegion
implementation which transfer data from a FileChannel
or File
.
Be aware that the FileChannel
will be automatically closed once AbstractReferenceCounted.refCnt()
returns
0
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final long
private final File
private FileChannel
private static final InternalLogger
private final long
private long
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultFileRegion
(File file, long position, long count) Create a new instance using the givenFile
.DefaultFileRegion
(FileChannel fileChannel, long position, long count) Create a new instance -
Method Summary
Modifier and TypeMethodDescriptionlong
count()
Returns the number of bytes to transfer.protected void
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.retain()
Increases the reference count by1
.retain
(int increment) Increases the reference count by the specifiedincrement
.touch()
Records the current access location of this object for debugging purposes.Records the current access location of this object with an additional arbitrary information for debugging purposes.long
Deprecated.long
Returns the bytes which was transferred already.long
transferTo
(WritableByteChannel target, long position) Transfers the content of this file region to the specified channel.(package private) static void
validate
(DefaultFileRegion region, long position) Methods inherited from class io.netty.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.netty.util.ReferenceCounted
refCnt, release, release
-
Field Details
-
logger
-
f
-
position
private final long position -
count
private final long count -
transferred
private long transferred -
file
-
-
Constructor Details
-
DefaultFileRegion
Create a new instance- Parameters:
fileChannel
- theFileChannel
which should be transferredposition
- the position from which the transfer should startcount
- the number of bytes to transfer
-
DefaultFileRegion
Create a new instance using the givenFile
. TheFile
will be opened lazily or explicitly viaopen()
.- Parameters:
file
- theFile
which should be transferredposition
- the position from which the transfer should startcount
- the number of bytes to transfer
-
-
Method Details
-
isOpen
public boolean isOpen()Returnstrue
if theFileRegion
has a open file-descriptor -
open
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.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
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
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
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
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
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
-
validate
- Throws:
IOException
-