Class FileTransfer

  • All Implemented Interfaces:
    WritableMessage, FileChunk

    public class FileTransfer
    extends java.lang.Object
    implements FileChunk
    A simple class that abstracts FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel) for use with Grizzly 2.0 AsyncQueueWriter.
    Since:
    2.2
    • Constructor Summary

      Constructors 
      Constructor Description
      FileTransfer​(java.io.File f)
      Constructs a new FileTransfer instance backed by the specified File.
      FileTransfer​(java.io.File f, long pos, long len)
      Constructs a new FileTransfer instance backed by the specified File.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasRemaining()
      Return true if this message has data remaining to be written.
      boolean isExternal()
      Returns true if the message represents an external resource (for example FileTransfer), which is not loaded in memory.
      boolean release()
      Perform message specific actions to release resources held by the entity backing this WritableMessage.
      int remaining()
      Return the number of bytes remaining to be written.
      long writeTo​(java.nio.channels.WritableByteChannel c)
      Transfers the File backing this FileTransfer to the specified WritableByteChannel.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileTransfer

        public FileTransfer​(java.io.File f)
        Constructs a new FileTransfer instance backed by the specified File. This simply calls this(f, 0, f.length).
        Parameters:
        f - the File to transfer.
        Throws:
        java.lang.NullPointerException - if f is null.
        See Also:
        FileTransfer(java.io.File, long, long)
      • FileTransfer

        public FileTransfer​(java.io.File f,
                            long pos,
                            long len)
        Constructs a new FileTransfer instance backed by the specified File. The content to transfer will begin at the specified offset, pos with the total transfer length being specified by len.
        Parameters:
        f - the File to transfer.
        pos - the offset within the File to start the transfer.
        len - the total number of bytes to transfer.
        Throws:
        java.lang.IllegalArgumentException - if f is null, does not exist, is not readable, or is a directory.
        java.lang.IllegalArgumentException - if pos or len are negative.
        java.lang.IllegalArgumentException - if len exceeds the number of bytes that may be transferred based on the provided offset and file length.
    • Method Detail

      • writeTo

        public long writeTo​(java.nio.channels.WritableByteChannel c)
                     throws java.io.IOException
        Transfers the File backing this FileTransfer to the specified WritableByteChannel.
        Specified by:
        writeTo in interface FileChunk
        Parameters:
        c - the WritableByteChannel
        Returns:
        the number of bytes that have been transferred
        Throws:
        java.io.IOException - if an error occurs while processing
        See Also:
        FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
      • hasRemaining

        public boolean hasRemaining()
        Return true if this message has data remaining to be written.
        Specified by:
        hasRemaining in interface WritableMessage
        Returns:
        true if this message has data remaining to be written.
      • remaining

        public int remaining()
        Return the number of bytes remaining to be written.
        Specified by:
        remaining in interface WritableMessage
        Returns:
        the number of bytes remaining to be written.
      • release

        public boolean release()
        Perform message specific actions to release resources held by the entity backing this WritableMessage.
        Specified by:
        release in interface WritableMessage
        Returns:
        true if successfully released
      • isExternal

        public boolean isExternal()
        Returns true if the message represents an external resource (for example FileTransfer), which is not loaded in memory.
        Specified by:
        isExternal in interface WritableMessage
        Returns:
        False, if the message is located in memory (like Buffer).