Package com.bc.ceres.binio.util
Class FileChannelIOHandler
- java.lang.Object
-
- com.bc.ceres.binio.util.FileChannelIOHandler
-
-
Constructor Summary
Constructors Constructor Description FileChannelIOHandler(FileChannel fileChannel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getMaxPosition()
Returns the current size of the backing file, array or stream.void
read(DataContext context, byte[] data, long position)
Reads a sequence of up todata.length
bytes into the given array starting from the the given position.void
write(DataContext context, byte[] data, long position)
Writes a sequence of up todata.length
bytes to the file, starting at the given position.
-
-
-
Constructor Detail
-
FileChannelIOHandler
public FileChannelIOHandler(FileChannel fileChannel)
-
-
Method Detail
-
read
public void read(DataContext context, byte[] data, long position) throws IOException
Description copied from interface:IOHandler
Reads a sequence of up todata.length
bytes into the given array starting from the the given position. If the position is greater than the file's current size then no bytes are read.A read operation might not fill the array, and in fact it might not read any bytes at all. Whether or not it does so, depends upon the state of the file, e.g. only bytes that remain in the file starting from the given position will be read.
- Specified by:
read
in interfaceIOHandler
- Parameters:
context
- The I/O context.data
- The data array into which bytes are to be transferred.position
- The file position at which the transfer is to begin; must be non-negative.- Throws:
IOException
- If an I/O error occurs.
-
write
public void write(DataContext context, byte[] data, long position) throws IOException
Description copied from interface:IOHandler
Writes a sequence of up todata.length
bytes to the file, starting at the given position. If the given position is greater than the file's current size then the file will be grown to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified.- Specified by:
write
in interfaceIOHandler
- Parameters:
context
- The I/O context.data
- The data array from which bytes are to be transferred.position
- The file position at which the transfer is to begin; must be non-negative.- Throws:
IOException
- If an I/O error occurs.
-
getMaxPosition
public long getMaxPosition() throws IOException
Description copied from interface:IOHandler
Returns the current size of the backing file, array or stream.This value may change, while writing to a growing file or array. If the value is unknown
-1
will be returned.- Specified by:
getMaxPosition
in interfaceIOHandler
- Returns:
- Te maximum position.
- Throws:
IOException
- If an I/O error occurs.
-
-