Class DefaultFileRegion

  • All Implemented Interfaces:
    FileRegion, io.netty.util.ReferenceCounted

    public class DefaultFileRegion
    extends io.netty.util.AbstractReferenceCounted
    implements FileRegion
    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 Detail

      • DefaultFileRegion

        public DefaultFileRegion​(FileChannel fileChannel,
                                 long position,
                                 long count)
        Create a new instance
        Parameters:
        fileChannel - the FileChannel which should be transferred
        position - the position from which the transfer should start
        count - the number of bytes to transfer
      • DefaultFileRegion

        public DefaultFileRegion​(File file,
                                 long position,
                                 long count)
        Create a new instance using the given File. The File will be opened lazily or explicitly via open().
        Parameters:
        file - the File which should be transferred
        position - the position from which the transfer should start
        count - the number of bytes to transfer
    • Method Detail

      • isOpen

        public boolean isOpen()
        Returns true if the FileRegion 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 interface FileRegion
      • count

        public long count()
        Description copied from interface: FileRegion
        Returns the number of bytes to transfer.
        Specified by:
        count in interface FileRegion
      • transfered

        @Deprecated
        public long transfered()
        Deprecated.
        Description copied from interface: FileRegion
        Returns the bytes which was transferred already.
        Specified by:
        transfered in interface FileRegion
      • transferred

        public long transferred()
        Description copied from interface: FileRegion
        Returns the bytes which was transferred already.

        Note: some asynchronous transports (such as the io_uring transport when falling back to a chunked send for non-DefaultFileRegion implementations) 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:
        transferred in interface FileRegion
      • 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 interface FileRegion
        Parameters:
        target - the destination of the transfer
        position - the relative offset of the file where the transfer begins from. For example, 0 will make the transfer start from FileRegion.position()th byte and FileRegion.count() - 1 will make the last byte of the region transferred.
        Throws:
        IOException
      • deallocate

        protected void deallocate()
        Specified by:
        deallocate in class io.netty.util.AbstractReferenceCounted
      • retain

        public FileRegion retain()
        Specified by:
        retain in interface FileRegion
        Specified by:
        retain in interface io.netty.util.ReferenceCounted
        Overrides:
        retain in class io.netty.util.AbstractReferenceCounted
      • retain

        public FileRegion retain​(int increment)
        Specified by:
        retain in interface FileRegion
        Specified by:
        retain in interface io.netty.util.ReferenceCounted
        Overrides:
        retain in class io.netty.util.AbstractReferenceCounted
      • touch

        public FileRegion touch()
        Specified by:
        touch in interface FileRegion
        Specified by:
        touch in interface io.netty.util.ReferenceCounted
        Overrides:
        touch in class io.netty.util.AbstractReferenceCounted
      • touch

        public FileRegion touch​(Object hint)
        Specified by:
        touch in interface FileRegion
        Specified by:
        touch in interface io.netty.util.ReferenceCounted