Class DefaultFileRegion

    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultFileRegion​(java.io.File file, long position, long count)
      Create a new instance using the given File.
      DefaultFileRegion​(java.nio.channels.FileChannel fileChannel, long position, long count)
      Create a new instance
    • Constructor Detail

      • DefaultFileRegion

        public DefaultFileRegion​(java.nio.channels.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​(java.io.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 java.io.IOException
        Explicitly open the underlying file-descriptor if not done yet.
        Throws:
        java.io.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​(java.nio.channels.WritableByteChannel target,
                               long position)
                        throws java.io.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:
        java.io.IOException
      • touch

        public FileRegion touch​(java.lang.Object hint)
        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 via ResourceLeakDetector.
        Specified by:
        touch in interface FileRegion
        Specified by:
        touch in interface ReferenceCounted