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.-
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 TypeMethodDescriptionlongcount()Returns the number of bytes to transfer.protected voidCalled onceAbstractReferenceCounted.refCnt()is equals 0.booleanisOpen()Returnstrueif theFileRegionhas a open file-descriptorvoidopen()Explicitly open the underlying file-descriptor if not done yet.longposition()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.longDeprecated.longReturns the bytes which was transferred already.longtransferTo(WritableByteChannel target, long position) Transfers the content of this file region to the specified channel.Methods inherited from class AbstractReferenceCounted
refCnt, release, release, setRefCntMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ReferenceCounted
refCnt, release, release
-
Constructor Details
-
DefaultFileRegion
Create a new instance- Parameters:
fileChannel- theFileChannelwhich should be transferredposition- the position from which the transfer should startcount- the number of bytes to transfer
-
DefaultFileRegion
-
-
Method Details
-
isOpen
public boolean isOpen()Returnstrueif theFileRegionhas 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:FileRegionReturns the offset in the file where the transfer began.- Specified by:
positionin interfaceFileRegion
-
count
public long count()Description copied from interface:FileRegionReturns the number of bytes to transfer.- Specified by:
countin interfaceFileRegion
-
transfered
Deprecated.Description copied from interface:FileRegionReturns the bytes which was transferred already.- Specified by:
transferedin interfaceFileRegion
-
transferred
public long transferred()Description copied from interface:FileRegionReturns the bytes which was transferred already.- Specified by:
transferredin interfaceFileRegion
-
transferTo
Description copied from interface:FileRegionTransfers the content of this file region to the specified channel.- Specified by:
transferToin 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:AbstractReferenceCountedCalled onceAbstractReferenceCounted.refCnt()is equals 0.- Specified by:
deallocatein classAbstractReferenceCounted
-
retain
Description copied from interface:ReferenceCountedIncreases the reference count by1.- Specified by:
retainin interfaceFileRegion- Specified by:
retainin interfaceReferenceCounted- Overrides:
retainin classAbstractReferenceCounted
-
retain
Description copied from interface:ReferenceCountedIncreases the reference count by the specifiedincrement.- Specified by:
retainin interfaceFileRegion- Specified by:
retainin interfaceReferenceCounted- Overrides:
retainin classAbstractReferenceCounted
-
touch
Description copied from interface:ReferenceCountedRecords 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:
touchin interfaceFileRegion- Specified by:
touchin interfaceReferenceCounted- Overrides:
touchin classAbstractReferenceCounted
-
touch
Description copied from interface:ReferenceCountedRecords 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:
touchin interfaceFileRegion- Specified by:
touchin interfaceReferenceCounted
-