Package org.glassfish.grizzly
Class FileTransfer
- java.lang.Object
-
- org.glassfish.grizzly.FileTransfer
-
- All Implemented Interfaces:
WritableMessage,FileChunk
public class FileTransfer extends Object implements FileChunk
A simple class that abstractsFileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)for use with Grizzly 2.0AsyncQueueWriter.- Since:
- 2.2
-
-
Constructor Summary
Constructors Constructor Description FileTransfer(File f)Constructs a newFileTransferinstance backed by the specifiedFile.FileTransfer(File f, long pos, long len)Constructs a newFileTransferinstance backed by the specifiedFile.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasRemaining()Returntrueif this message has data remaining to be written.booleanisExternal()Returns true if the message represents an external resource (for exampleFileTransfer), which is not loaded in memory.booleanrelease()Perform message specific actions to release resources held by the entity backing thisWritableMessage.intremaining()Return the number of bytes remaining to be written.longwriteTo(WritableByteChannel c)Transfers the File backing thisFileTransferto the specifiedWritableByteChannel.
-
-
-
Constructor Detail
-
FileTransfer
public FileTransfer(File f)
Constructs a newFileTransferinstance backed by the specifiedFile. This simply callsthis(f, 0, f.length).- Parameters:
f- theFileto transfer.- Throws:
NullPointerException- if f is null.- See Also:
FileTransfer(java.io.File, long, long)
-
FileTransfer
public FileTransfer(File f, long pos, long len)
Constructs a newFileTransferinstance backed by the specifiedFile. The content to transfer will begin at the specified offset,poswith the total transfer length being specified bylen.- Parameters:
f- theFileto transfer.pos- the offset within the File to start the transfer.len- the total number of bytes to transfer.- Throws:
IllegalArgumentException- iffis null, does not exist, is not readable, or is a directory.IllegalArgumentException- ifposorlenare negative.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(WritableByteChannel c) throws IOException
Transfers the File backing thisFileTransferto the specifiedWritableByteChannel.- Specified by:
writeToin interfaceFileChunk- Parameters:
c- theWritableByteChannel- Returns:
- the number of bytes that have been transferred
- Throws:
IOException- if an error occurs while processing- See Also:
FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
-
hasRemaining
public boolean hasRemaining()
Returntrueif this message has data remaining to be written.- Specified by:
hasRemainingin interfaceWritableMessage- Returns:
trueif this message has data remaining to be written.
-
remaining
public int remaining()
Return the number of bytes remaining to be written.- Specified by:
remainingin interfaceWritableMessage- 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 thisWritableMessage.- Specified by:
releasein interfaceWritableMessage- Returns:
- true if successfully released
-
isExternal
public boolean isExternal()
Returns true if the message represents an external resource (for exampleFileTransfer), which is not loaded in memory.- Specified by:
isExternalin interfaceWritableMessage- Returns:
- False, if the message is located in memory (like
Buffer).
-
-