java.lang.Object
org.glassfish.grizzly.FileTransfer
- All Implemented Interfaces:
WritableMessage,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
ConstructorsConstructorDescriptionFileTransfer(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
Modifier and TypeMethodDescriptionbooleanReturntrueif this message has data remaining to be written.booleanReturns 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.intReturn the number of bytes remaining to be written.longTransfers the File backing thisFileTransferto the specifiedWritableByteChannel.
-
Constructor Details
-
FileTransfer
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
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 Details
-
writeTo
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:
-
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).
-