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 newFileTransfer
instance backed by the specifiedFile
.FileTransfer(File f, long pos, long len)
Constructs a newFileTransfer
instance backed by the specifiedFile
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasRemaining()
Returntrue
if this message has data remaining to be written.boolean
isExternal()
Returns true if the message represents an external resource (for exampleFileTransfer
), which is not loaded in memory.boolean
release()
Perform message specific actions to release resources held by the entity backing thisWritableMessage
.int
remaining()
Return the number of bytes remaining to be written.long
writeTo(WritableByteChannel c)
Transfers the File backing thisFileTransfer
to the specifiedWritableByteChannel
.
-
-
-
Constructor Detail
-
FileTransfer
public FileTransfer(File f)
Constructs a newFileTransfer
instance backed by the specifiedFile
. This simply callsthis(f, 0, f.length)
.- Parameters:
f
- theFile
to 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 newFileTransfer
instance backed by the specifiedFile
. The content to transfer will begin at the specified offset,pos
with the total transfer length being specified bylen
.- Parameters:
f
- theFile
to transfer.pos
- the offset within the File to start the transfer.len
- the total number of bytes to transfer.- Throws:
IllegalArgumentException
- iff
is null, does not exist, is not readable, or is a directory.IllegalArgumentException
- ifpos
orlen
are 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 thisFileTransfer
to the specifiedWritableByteChannel
.- Specified by:
writeTo
in 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()
Returntrue
if this message has data remaining to be written.- Specified by:
hasRemaining
in interfaceWritableMessage
- 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 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:
release
in 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:
isExternal
in interfaceWritableMessage
- Returns:
- False, if the message is located in memory (like
Buffer
).
-
-