Package loci.common
Class NIOByteBufferProvider
java.lang.Object
loci.common.NIOByteBufferProvider
public class NIOByteBufferProvider
extends java.lang.Object
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
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(java.nio.channels.FileChannel channel, java.nio.channels.FileChannel.MapMode mapMode)
Default constructor. -
Method Summary
Modifier and Type Method Description java.nio.ByteBuffer
allocate(long bufferStartPosition, int newSize)
Allocates or maps the desired file data into memory.protected java.nio.ByteBuffer
allocateDirect(long bufferStartPosition, int newSize)
Allocates memory and copies the desired file data into it.protected java.nio.ByteBuffer
allocateMappedByteBuffer(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:
- Constant Field Values
-
-
Constructor Details
-
NIOByteBufferProvider
public NIOByteBufferProvider(java.nio.channels.FileChannel channel, java.nio.channels.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 Details
-
allocate
public java.nio.ByteBuffer allocate(long bufferStartPosition, int newSize) throws java.io.IOExceptionAllocates 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:
java.io.IOException
- If there is an issue mapping, aligning or allocating the buffer.
-
allocateDirect
protected java.nio.ByteBuffer allocateDirect(long bufferStartPosition, int newSize) throws java.io.IOExceptionAllocates 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:
java.io.IOException
- If there is an issue aligning or allocating the buffer.
-
allocateMappedByteBuffer
protected java.nio.ByteBuffer allocateMappedByteBuffer(long bufferStartPosition, int newSize) throws java.io.IOExceptionMemory 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:
java.io.IOException
- If there is an issue mapping, aligning or allocating the buffer.
-