Top Description Fields Constructors Methods
org.glassfish.grizzly

public Class FileTransfer

extends Object
implements FileChunk
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.FileChunk, org.glassfish.grizzly.asyncqueue.WritableMessage
Imports
java.io.File, .FileInputStream, .FileNotFoundException, .IOException, java.nio.channels.FileChannel, .WritableByteChannel

A simple class that abstracts FileChannel#transferTo(long, long, java.nio.channels.WritableByteChannel) for use with Grizzly 2.0 org.glassfish.grizzly.asyncqueue.AsyncQueueWriter.
Since
2.2

Field Summary

Modifier and TypeField and Description
private FileChannel
private long
private long

Constructor Summary

AccessConstructor and Description
public
FileTransfer(final File
the File to transfer.
f
)

Constructs a new FileTransfer instance backed by the specified File.

public
FileTransfer(final File
the File to transfer.
f
,
final long
the offset within the File to start the transfer.
pos
,
final long
the total number of bytes to transfer.
len
)

Constructs a new FileTransfer instance backed by the specified File.

Method Summary

Modifier and TypeMethod and Description
public boolean
hasRemaining()

Implements org.glassfish.grizzly.asyncqueue.WritableMessage.hasRemaining.

Return true if this message has data remaining to be written.

public boolean
isExternal()

Implements org.glassfish.grizzly.asyncqueue.WritableMessage.isExternal.

Returns true if the message represents an external resource (for example org.glassfish.grizzly.FileTransfer), which is not loaded in memory.

public boolean
release()

Implements org.glassfish.grizzly.asyncqueue.WritableMessage.release.

Perform message specific actions to release resources held by the entity backing this WritableMessage.

public int
remaining()

Implements org.glassfish.grizzly.asyncqueue.WritableMessage.remaining.

Return the number of bytes remaining to be written.

public long

Returns:

the number of bytes that have been transferred
writeTo
(final WritableByteChannel c)

Implements org.glassfish.grizzly.FileChunk.writeTo.

Transfers the File backing this FileTransfer to the specified WritableByteChannel.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fileChannelback to summary
private FileChannel fileChannel
lenback to summary
private long len
posback to summary
private long pos

Constructor Detail

FileTransferback to summary
public FileTransfer(final File f)

Constructs a new FileTransfer instance backed by the specified File. This simply calls this(f, 0, f.length).

Parameters
f:File

the File to transfer.

Exceptions
NullPointerException:
if f is null.
See Also
FileTransfer(java.io.File, long, long)
FileTransferback to summary
public FileTransfer(final File f, final long pos, final 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:File

the File to transfer.

pos:long

the offset within the File to start the transfer.

len:long

the total number of bytes to transfer.

Exceptions
IllegalArgumentException:
  • if f is null, does not exist, is not readable, or is a directory.
  • if pos or len are negative.
  • if len exceeds the number of bytes that may be transferred based on the provided offset and file length.

Method Detail

hasRemainingback to summary
public boolean hasRemaining()

Implements org.glassfish.grizzly.asyncqueue.WritableMessage.hasRemaining.

Doc from org.glassfish.grizzly.asyncqueue.WritableMessage.hasRemaining.

Return true if this message has data remaining to be written.

Annotations
@Override
isExternalback to summary
public boolean isExternal()

Implements org.glassfish.grizzly.asyncqueue.WritableMessage.isExternal.

Doc from org.glassfish.grizzly.asyncqueue.WritableMessage.isExternal.

Returns true if the message represents an external resource (for example org.glassfish.grizzly.FileTransfer), which is not loaded in memory.

Annotations
@Override
releaseback to summary
public boolean release()

Implements org.glassfish.grizzly.asyncqueue.WritableMessage.release.

Doc from org.glassfish.grizzly.asyncqueue.WritableMessage.release.

Perform message specific actions to release resources held by the entity backing this WritableMessage.

Annotations
@Override
remainingback to summary
public int remaining()

Implements org.glassfish.grizzly.asyncqueue.WritableMessage.remaining.

Doc from org.glassfish.grizzly.asyncqueue.WritableMessage.remaining.

Return the number of bytes remaining to be written.

Annotations
@Override
writeToback to summary
public long writeTo(final WritableByteChannel c) throws IOException

Implements org.glassfish.grizzly.FileChunk.writeTo.

Transfers the File backing this FileTransfer to the specified WritableByteChannel.

Parameters
c:WritableByteChannel

the WritableByteChannel

Returns:long

the number of bytes that have been transferred

Exceptions
IOException:
if an error occurs while processing
See Also
java.nio.channels.FileChannel#transferTo(long, long, java.nio.channels.WritableByteChannel)