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 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.- Author:
- Apache MINA Project
-
-
Constructor Summary
Constructors Constructor Description DefaultFileRegion(FileChannel channel)
Creates a new DefaultFileRegion instanceDefaultFileRegion(FileChannel channel, long position, long remainingBytes)
Creates a new DefaultFileRegion instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileChannel
getFileChannel()
The open FileChannel from which data will be read to send to remote host.String
getFilename()
Provides an absolute filename for the underlying FileChannel.long
getPosition()
The current file position from which data will be read.long
getRemainingBytes()
The number of bytes remaining to be written from the file to the remote host.long
getWrittenBytes()
The total number of bytes already written.void
update(long value)
Updates the current file position based on the specified amount.
-
-
-
Constructor Detail
-
DefaultFileRegion
public DefaultFileRegion(FileChannel channel) throws IOException
Creates a new DefaultFileRegion instance- Parameters:
channel
- The channel mapped over the file- Throws:
IOException
- If we had an IO error
-
DefaultFileRegion
public DefaultFileRegion(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:
getWrittenBytes
in 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:
getRemainingBytes
in interfaceFileRegion
- Returns:
- The number of bytes remaining to be written.
-
getFileChannel
public FileChannel getFileChannel()
The open FileChannel from which data will be read to send to remote host.- Specified by:
getFileChannel
in interfaceFileRegion
- Returns:
- An open FileChannel.
-
getPosition
public long getPosition()
The current file position from which data will be read.- Specified by:
getPosition
in 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:
update
in interfaceFileRegion
- Parameters:
value
- The new value for the file position.
-
getFilename
public String getFilename()
Provides an absolute filename for the underlying FileChannel.- Specified by:
getFilename
in interfaceFileRegion
- Returns:
- the absolute filename, or null if the FileRegion does not know the filename
-
-