public abstract class BlockMappedInput extends java.lang.Object implements BasicInput
Note: DO NOT use an instance
of this class from multiple threads - see Unmapper
.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BLOCKSIZE
Default maximum size in bytes for mapped blocks.
|
static long |
DEFAULT_EXPIRYMILLIS
Default time in milliseconds after which buffers will be discarded.
|
Modifier | Constructor and Description |
---|---|
protected |
BlockMappedInput(java.nio.channels.FileChannel channel,
long pos,
long size,
java.lang.String logName,
int blockSize)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected abstract java.nio.MappedByteBuffer |
acquireBlock(int iblock)
Obtains a buffer corresponding to a named block of the stream.
|
static BlockMappedInput |
createInput(java.nio.channels.FileChannel channel,
long pos,
long size,
java.lang.String logName,
boolean caching)
Constructs an instance that does or does not support caching.
|
static BlockMappedInput |
createInput(java.nio.channels.FileChannel channel,
long pos,
long size,
java.lang.String logName,
int blockSize,
long expiryMillis)
Constructs an instance with explicit configuration.
|
int |
getBlockCount()
Returns the number of mapped blocks used.
|
long |
getOffset()
Returns the curent position in this stream
(optional operation).
|
boolean |
isRandom()
Indicates whether this object supports random access.
|
byte |
readByte()
Reads a byte from the stream.
|
double |
readDouble()
Reads an 8-byte floating point value from the stream.
|
float |
readFloat()
Reads a 4-byte floating point value from the stream.
|
int |
readInt()
Reads a 4-byte integer from the stream.
|
long |
readLong()
Reads an 8-byte integer from the stream.
|
short |
readShort()
Reads a 2-byte integer from the stream.
|
void |
seek(long offset)
Moves the current position of this stream to a given byte offset
(optional operation).
|
void |
skip(long nbyte)
Skips a given number of bytes forwards through the stream.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
public static final int DEFAULT_BLOCKSIZE
public static final long DEFAULT_EXPIRYMILLIS
protected BlockMappedInput(java.nio.channels.FileChannel channel, long pos, long size, java.lang.String logName, int blockSize) throws java.io.IOException
channel
- file channel, preferably read-onlypos
- offset into file of stream startsize
- number of bytes in streamlogName
- name for mapped region used in logging messagesblockSize
- (maximum) number of bytes per mapped blockjava.io.IOException
public byte readByte() throws java.io.IOException
BasicInput
readByte
in interface BasicInput
java.io.IOException
public short readShort() throws java.io.IOException
BasicInput
readShort
in interface BasicInput
java.io.IOException
public int readInt() throws java.io.IOException
BasicInput
readInt
in interface BasicInput
java.io.IOException
public long readLong() throws java.io.IOException
BasicInput
readLong
in interface BasicInput
java.io.IOException
public float readFloat() throws java.io.IOException
BasicInput
readFloat
in interface BasicInput
java.io.IOException
public double readDouble() throws java.io.IOException
BasicInput
readDouble
in interface BasicInput
java.io.IOException
public boolean isRandom()
BasicInput
isRandom
in interface BasicInput
public void seek(long offset) throws java.io.IOException
BasicInput
seek
in interface BasicInput
java.io.IOException
public long getOffset()
BasicInput
getOffset
in interface BasicInput
public void skip(long nbyte) throws java.io.IOException
BasicInput
skip
in interface BasicInput
nbyte
- number of bytes to skipjava.io.IOException
public int getBlockCount()
protected abstract java.nio.MappedByteBuffer acquireBlock(int iblock) throws java.io.IOException
iblock
- block indexjava.io.IOException
public static BlockMappedInput createInput(java.nio.channels.FileChannel channel, long pos, long size, java.lang.String logName, boolean caching) throws java.io.IOException
channel
- file channel, preferably read-onlypos
- offset into file of stream startsize
- number of bytes in streamlogName
- name for mapped region used in logging messagescaching
- whether buffers are cachedjava.io.IOException
public static BlockMappedInput createInput(java.nio.channels.FileChannel channel, long pos, long size, java.lang.String logName, int blockSize, long expiryMillis) throws java.io.IOException
expiryMillis
parameter controls caching.
If zero, the current buffer is discarded an unmapped as soon
as a different one is used. Otherwise, an attempt is made to
discard buffers only after they have been unused for a certain
number of milliseconds.channel
- file channel, preferably read-onlypos
- offset into file of stream startsize
- number of bytes in streamlogName
- name for mapped region used in logging messagesblockSize
- maximum number of bytes per blockexpiryMillis
- buffer caching period in millisecondsjava.io.IOException
Copyright © 2017 Central Laboratory of the Research Councils. All Rights Reserved.