|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.ac.starlink.fits.BlockMappedInput
public abstract class BlockMappedInput
Random-access BasicInput implementation that maps a given region of a file as a number of byte buffers. The most recently-used buffer is always kept, but there is a choice of what to do with less-recently used ones. Concrete subclasses are provided that either discard them automatically or keep them around for a period of time before discarding them. If and when a buffer is discarded, an attempt is made to unmap it.
Note: DO NOT use an instance
of this class from multiple threads - see Unmapper
.
Field Summary | |
---|---|
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. |
Constructor Summary | |
---|---|
protected |
BlockMappedInput(FileChannel channel,
long pos,
long size,
String logName,
int blockSize)
Constructor. |
Method Summary | |
---|---|
protected abstract MappedByteBuffer |
acquireBlock(int iblock)
Obtains a buffer corresponding to a named block of the stream. |
static BlockMappedInput |
createInput(FileChannel channel,
long pos,
long size,
String logName,
boolean caching)
Constructs an instance that does or does not support caching. |
static BlockMappedInput |
createInput(FileChannel channel,
long pos,
long size,
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface uk.ac.starlink.fits.BasicInput |
---|
close |
Field Detail |
---|
public static final int DEFAULT_BLOCKSIZE
public static final long DEFAULT_EXPIRYMILLIS
Constructor Detail |
---|
protected BlockMappedInput(FileChannel channel, long pos, long size, String logName, int blockSize) throws 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 block
IOException
Method Detail |
---|
public byte readByte() throws IOException
BasicInput
readByte
in interface BasicInput
IOException
public short readShort() throws IOException
BasicInput
readShort
in interface BasicInput
IOException
public int readInt() throws IOException
BasicInput
readInt
in interface BasicInput
IOException
public long readLong() throws IOException
BasicInput
readLong
in interface BasicInput
IOException
public float readFloat() throws IOException
BasicInput
readFloat
in interface BasicInput
IOException
public double readDouble() throws IOException
BasicInput
readDouble
in interface BasicInput
IOException
public boolean isRandom()
BasicInput
isRandom
in interface BasicInput
public void seek(long offset) throws IOException
BasicInput
seek
in interface BasicInput
IOException
public long getOffset()
BasicInput
getOffset
in interface BasicInput
public void skip(long nbyte) throws IOException
BasicInput
skip
in interface BasicInput
nbyte
- number of bytes to skip
IOException
public int getBlockCount()
protected abstract MappedByteBuffer acquireBlock(int iblock) throws IOException
iblock
- block index
IOException
public static BlockMappedInput createInput(FileChannel channel, long pos, long size, String logName, boolean caching) throws 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 cached
IOException
public static BlockMappedInput createInput(FileChannel channel, long pos, long size, String logName, int blockSize, long expiryMillis) throws 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 milliseconds
IOException
|
Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |