public abstract class BlockMappedInput extends BlockInput
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 |
---|---|
void |
close()
Releases resources belonging to this object.
|
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.
|
long |
getBlockOffset(int iblock,
int offsetInBlock)
Returns the offset into this stream corresponding to a given
block index and offset into that block.
|
int[] |
getBlockPos(long offset)
Returns the block location of a given byte offset.
|
acquireBlock, getBlockCount, getOffset, isRandom, readByte, readBytes, readDouble, readFloat, readInt, readLong, readShort, seek, skip
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 int[] getBlockPos(long offset)
BlockInput
This does the opposite of getBlockOffset
.
getBlockPos
in class BlockInput
offset
- offset into this input streampublic long getBlockOffset(int iblock, int offsetInBlock)
BlockInput
This does the opposite of getBlockPos
.
getBlockOffset
in class BlockInput
iblock
- block indexoffsetInBlock
- offset into that blockpublic void close()
BasicInput
close
in interface BasicInput
close
in class BlockInput
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