Package io.netty.channel
Class DefaultFileRegion
- java.lang.Object
-
- io.netty.util.AbstractReferenceCounted
-
- io.netty.channel.DefaultFileRegion
-
- All Implemented Interfaces:
FileRegion,ReferenceCounted
public class DefaultFileRegion extends AbstractReferenceCounted implements FileRegion
DefaultFileRegionimplementation which transfer data from aFileChannelorFile. Be aware that theFileChannelwill be automatically closed onceAbstractReferenceCounted.refCnt()returns0.
-
-
Constructor Summary
Constructors Constructor Description DefaultFileRegion(java.io.File file, long position, long count)Create a new instance using the givenFile.DefaultFileRegion(java.nio.channels.FileChannel fileChannel, long position, long count)Create a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description longcount()Returns the number of bytes to transfer.protected voiddeallocate()Called 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.FileRegionretain()Increases the reference count by1.FileRegionretain(int increment)Increases the reference count by the specifiedincrement.FileRegiontouch()Records the current access location of this object for debugging purposes.FileRegiontouch(java.lang.Object hint)Records the current access location of this object with an additional arbitrary information for debugging purposes.longtransfered()Deprecated.longtransferred()Returns the bytes which was transferred already.longtransferTo(java.nio.channels.WritableByteChannel target, long position)Transfers the content of this file region to the specified channel.-
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
-
-
-
-
Constructor Detail
-
DefaultFileRegion
public DefaultFileRegion(java.nio.channels.FileChannel fileChannel, long position, long count)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
public DefaultFileRegion(java.io.File file, long position, long count)Create a new instance using the givenFile. TheFilewill be opened lazily or explicitly viaopen().- Parameters:
file- theFilewhich should be transferredposition- the position from which the transfer should startcount- the number of bytes to transfer
-
-
Method Detail
-
isOpen
public boolean isOpen()
Returnstrueif theFileRegionhas a open file-descriptor
-
open
public void open() throws java.io.IOExceptionExplicitly open the underlying file-descriptor if not done yet.- Throws:
java.io.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 public long 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
public long transferTo(java.nio.channels.WritableByteChannel target, long position) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
deallocate
protected void deallocate()
Description copied from class:AbstractReferenceCountedCalled onceAbstractReferenceCounted.refCnt()is equals 0.- Specified by:
deallocatein classAbstractReferenceCounted
-
retain
public FileRegion retain()
Description copied from interface:ReferenceCountedIncreases the reference count by1.- Specified by:
retainin interfaceFileRegion- Specified by:
retainin interfaceReferenceCounted- Overrides:
retainin classAbstractReferenceCounted
-
retain
public FileRegion retain(int increment)
Description copied from interface:ReferenceCountedIncreases the reference count by the specifiedincrement.- Specified by:
retainin interfaceFileRegion- Specified by:
retainin interfaceReferenceCounted- Overrides:
retainin classAbstractReferenceCounted
-
touch
public FileRegion 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
public FileRegion touch(java.lang.Object hint)
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
-
-