public class NIOByteBufferProvider extends Object
FileChannel.map()
usage on platforms where it's unlikely to
give us problems and heap allocation where it is. References:
Modifier and Type | Field and Description |
---|---|
private FileChannel |
channel
File channel to allocate or map data from.
|
private static org.slf4j.Logger |
LOGGER
Logger for this class.
|
private FileChannel.MapMode |
mapMode
If we are to use memory mapped I/O, the map mode.
|
static int |
MINIMUM_JAVA_VERSION
The minimum Java version we know is safe for memory mapped I/O.
|
private static boolean |
useMappedByteBuffer
Whether or not we are to use memory mapped I/O.
|
Constructor and Description |
---|
NIOByteBufferProvider(FileChannel channel,
FileChannel.MapMode mapMode)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
ByteBuffer |
allocate(long bufferStartPosition,
int newSize)
Allocates or maps the desired file data into memory.
|
protected ByteBuffer |
allocateDirect(long bufferStartPosition,
int newSize)
Allocates memory and copies the desired file data into it.
|
protected ByteBuffer |
allocateMappedByteBuffer(long bufferStartPosition,
int newSize)
Memory maps the desired file data into memory.
|
public static final int MINIMUM_JAVA_VERSION
private static final org.slf4j.Logger LOGGER
private static boolean useMappedByteBuffer
private FileChannel channel
private FileChannel.MapMode mapMode
public NIOByteBufferProvider(FileChannel channel, FileChannel.MapMode mapMode)
channel
- File channel to allocate or map byte buffers from.mapMode
- The map mode. Required but only used if memory mapped I/O
is to occur.public ByteBuffer allocate(long bufferStartPosition, int newSize) throws IOException
bufferStartPosition
- The absolute position of the start of the
buffer.newSize
- The buffer size.IOException
- If there is an issue mapping, aligning or allocating
the buffer.protected ByteBuffer allocateDirect(long bufferStartPosition, int newSize) throws IOException
bufferStartPosition
- The absolute position of the start of the
buffer.newSize
- The buffer size.IOException
- If there is an issue aligning or allocating
the buffer.protected ByteBuffer allocateMappedByteBuffer(long bufferStartPosition, int newSize) throws IOException
bufferStartPosition
- The absolute position of the start of the
buffer.newSize
- The buffer size.IOException
- If there is an issue mapping, aligning or allocating
the buffer.Copyright © 2016 Open Microscopy Environment