Package loci.common
Class NIOByteBufferProvider
java.lang.Object
loci.common.NIOByteBufferProvider
Provides a facade to byte buffer allocation that enables
FileChannel.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
FieldsModifier and TypeFieldDescriptionstatic final intThe minimum Java version we know is safe for memory mapped I/O. -
Constructor Summary
ConstructorsConstructorDescriptionNIOByteBufferProvider(FileChannel channel, FileChannel.MapMode mapMode) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionallocate(long bufferStartPosition, int newSize) Allocates or maps the desired file data into memory.protected ByteBufferallocateDirect(long bufferStartPosition, int newSize) Allocates memory and copies the desired file data into it.protected ByteBufferallocateMappedByteBuffer(long bufferStartPosition, int newSize) Memory maps the desired file data into memory.
-
Field Details
-
MINIMUM_JAVA_VERSION
public static final int MINIMUM_JAVA_VERSIONThe minimum Java version we know is safe for memory mapped I/O.- See Also:
-
-
Constructor Details
-
NIOByteBufferProvider
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 Details
-
allocate
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
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.
-