|
|||||||||
| 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(java.nio.channels.FileChannel channel,
long pos,
long size,
java.lang.String logName,
int blockSize)
Constructor. |
| Method Summary | |
|---|---|
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. |
| 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(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 block
java.io.IOException| Method Detail |
|---|
public byte readByte()
throws java.io.IOException
BasicInput
readByte in interface BasicInputjava.io.IOException
public short readShort()
throws java.io.IOException
BasicInput
readShort in interface BasicInputjava.io.IOException
public int readInt()
throws java.io.IOException
BasicInput
readInt in interface BasicInputjava.io.IOException
public long readLong()
throws java.io.IOException
BasicInput
readLong in interface BasicInputjava.io.IOException
public float readFloat()
throws java.io.IOException
BasicInput
readFloat in interface BasicInputjava.io.IOException
public double readDouble()
throws java.io.IOException
BasicInput
readDouble in interface BasicInputjava.io.IOExceptionpublic boolean isRandom()
BasicInput
isRandom in interface BasicInput
public void seek(long offset)
throws java.io.IOException
BasicInput
seek in interface BasicInputjava.io.IOExceptionpublic long getOffset()
BasicInput
getOffset in interface BasicInput
public void skip(long nbyte)
throws java.io.IOException
BasicInput
skip in interface BasicInputnbyte - number of bytes to skip
java.io.IOExceptionpublic int getBlockCount()
protected abstract java.nio.MappedByteBuffer acquireBlock(int iblock)
throws java.io.IOException
iblock - block index
java.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 cached
java.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 milliseconds
java.io.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 | ||||||||