Package org.apache.mina.core.file
Class DefaultFileRegion
- java.lang.Object
-
- org.apache.mina.core.file.DefaultFileRegion
-
- All Implemented Interfaces:
FileRegion
- Direct Known Subclasses:
FilenameFileRegion
public class DefaultFileRegion extends java.lang.Object implements FileRegion
Manage a File to be sent to a remote host. We keep a track on the current position, and the number of already written bytes.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.channels.FileChannelchannelThe channel used to manage the fileprivate longoriginalPositionThe original position in the fileprivate longpositionThe position in teh fileprivate longremainingBytesThe number of bytes remaining to write
-
Constructor Summary
Constructors Constructor Description DefaultFileRegion(java.nio.channels.FileChannel channel)Creates a new DefaultFileRegion instanceDefaultFileRegion(java.nio.channels.FileChannel channel, long position, long remainingBytes)Creates a new DefaultFileRegion instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.channels.FileChannelgetFileChannel()The openFileChannelfrom which data will be read to send to remote host.java.lang.StringgetFilename()Provides an absolute filename for the underlying FileChannel.longgetPosition()The current file position from which data will be read.longgetRemainingBytes()The number of bytes remaining to be written from the file to the remote host.longgetWrittenBytes()The total number of bytes already written.voidupdate(long value)Updates the current file position based on the specified amount.
-
-
-
Field Detail
-
channel
private final java.nio.channels.FileChannel channel
The channel used to manage the file
-
originalPosition
private final long originalPosition
The original position in the file
-
position
private long position
The position in teh file
-
remainingBytes
private long remainingBytes
The number of bytes remaining to write
-
-
Constructor Detail
-
DefaultFileRegion
public DefaultFileRegion(java.nio.channels.FileChannel channel) throws java.io.IOExceptionCreates a new DefaultFileRegion instance- Parameters:
channel- The channel mapped over the file- Throws:
java.io.IOException- If we had an IO error
-
DefaultFileRegion
public DefaultFileRegion(java.nio.channels.FileChannel channel, long position, long remainingBytes)Creates a new DefaultFileRegion instance- Parameters:
channel- The channel mapped over the fileposition- The position in teh fileremainingBytes- The remaining bytes
-
-
Method Detail
-
getWrittenBytes
public long getWrittenBytes()
The total number of bytes already written.- Specified by:
getWrittenBytesin interfaceFileRegion- Returns:
- The total number of bytes already written.
-
getRemainingBytes
public long getRemainingBytes()
The number of bytes remaining to be written from the file to the remote host.- Specified by:
getRemainingBytesin interfaceFileRegion- Returns:
- The number of bytes remaining to be written.
-
getFileChannel
public java.nio.channels.FileChannel getFileChannel()
The openFileChannelfrom which data will be read to send to remote host.- Specified by:
getFileChannelin interfaceFileRegion- Returns:
- An open
FileChannel.
-
getPosition
public long getPosition()
The current file position from which data will be read.- Specified by:
getPositionin interfaceFileRegion- Returns:
- The current file position.
-
update
public void update(long value)
Updates the current file position based on the specified amount. This increases the value returned byFileRegion.getPosition()andFileRegion.getWrittenBytes()by the given amount and decreases the value returned byFileRegion.getRemainingBytes()by the givenamount.- Specified by:
updatein interfaceFileRegion- Parameters:
value- The new value for the file position.
-
getFilename
public java.lang.String getFilename()
Provides an absolute filename for the underlying FileChannel.- Specified by:
getFilenamein interfaceFileRegion- Returns:
- the absolute filename, or
nullif the FileRegion does not know the filename
-
-