Package loci.common
Class NIOByteBufferProvider
- java.lang.Object
-
- loci.common.NIOByteBufferProvider
-
public class NIOByteBufferProvider extends Object
Provides a facade to byte buffer allocation that enablesFileChannel.map()
usage on platforms where it's unlikely to give us problems and heap allocation where it is. References:- http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5092131
- http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6417205
- Author:
- Chris Allan (callan at blackcat dot ca)
-
-
Field Summary
Fields Modifier and Type Field Description static int
MINIMUM_JAVA_VERSION
The minimum Java version we know is safe for memory mapped I/O.
-
Constructor Summary
Constructors Constructor Description NIOByteBufferProvider(FileChannel channel, FileChannel.MapMode mapMode)
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
MINIMUM_JAVA_VERSION
public static final int MINIMUM_JAVA_VERSION
The minimum Java version we know is safe for memory mapped I/O.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NIOByteBufferProvider
public NIOByteBufferProvider(FileChannel channel, FileChannel.MapMode mapMode)
Default constructor.- Parameters:
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.
-
-
Method Detail
-
allocate
public ByteBuffer allocate(long bufferStartPosition, int newSize) throws IOException
Allocates or maps the desired file data into memory.- Parameters:
bufferStartPosition
- The absolute position of the start of the buffer.newSize
- The buffer size.- Returns:
- A newly allocated or mapped NIO byte buffer.
- Throws:
IOException
- If there is an issue mapping, aligning or allocating the buffer.
-
allocateDirect
protected ByteBuffer allocateDirect(long bufferStartPosition, int newSize) throws IOException
Allocates memory and copies the desired file data into it.- Parameters:
bufferStartPosition
- The absolute position of the start of the buffer.newSize
- The buffer size.- Returns:
- A newly allocated NIO byte buffer.
- Throws:
IOException
- If there is an issue aligning or allocating the buffer.
-
allocateMappedByteBuffer
protected ByteBuffer allocateMappedByteBuffer(long bufferStartPosition, int newSize) throws IOException
Memory maps the desired file data into memory.- Parameters:
bufferStartPosition
- The absolute position of the start of the buffer.newSize
- The buffer size.- Returns:
- A newly mapped NIO byte buffer.
- Throws:
IOException
- If there is an issue mapping, aligning or allocating the buffer.
-
-