Package io.netty.channel
Class DefaultFileRegion
- java.lang.Object
-
- io.netty.util.AbstractReferenceCounted
-
- io.netty.channel.DefaultFileRegion
-
- All Implemented Interfaces:
FileRegion,io.netty.util.ReferenceCounted
public class DefaultFileRegion extends io.netty.util.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(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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description longcount()Returns the number of bytes to transfer.protected voiddeallocate()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()FileRegionretain(int increment)FileRegiontouch()FileRegiontouch(Object hint)longtransfered()Deprecated.longtransferred()Returns 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 io.netty.util.AbstractReferenceCounted
refCnt, release, release, setRefCnt
-
-
-
-
Constructor Detail
-
DefaultFileRegion
public DefaultFileRegion(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(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 IOExceptionExplicitly 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 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.Note: some asynchronous transports (such as the
io_uringtransport when falling back to a chunked send for non-DefaultFileRegionimplementations) advance this counter when bytes have been queued for submission, which may be before they reach the peer. If the channel is closed or the write fails after queuing, the reported value may overstate the number of bytes actually delivered.- Specified by:
transferredin interfaceFileRegion
-
transferTo
public long transferTo(WritableByteChannel target, long position) throws IOException
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()
- Specified by:
deallocatein classio.netty.util.AbstractReferenceCounted
-
retain
public FileRegion retain()
- Specified by:
retainin interfaceFileRegion- Specified by:
retainin interfaceio.netty.util.ReferenceCounted- Overrides:
retainin classio.netty.util.AbstractReferenceCounted
-
retain
public FileRegion retain(int increment)
- Specified by:
retainin interfaceFileRegion- Specified by:
retainin interfaceio.netty.util.ReferenceCounted- Overrides:
retainin classio.netty.util.AbstractReferenceCounted
-
touch
public FileRegion touch()
- Specified by:
touchin interfaceFileRegion- Specified by:
touchin interfaceio.netty.util.ReferenceCounted- Overrides:
touchin classio.netty.util.AbstractReferenceCounted
-
touch
public FileRegion touch(Object hint)
- Specified by:
touchin interfaceFileRegion- Specified by:
touchin interfaceio.netty.util.ReferenceCounted
-
-