uk.ac.starlink.fits
Class SimpleMappedInput

java.lang.Object
  extended by uk.ac.starlink.fits.SimpleMappedInput
All Implemented Interfaces:
BasicInput

public class SimpleMappedInput
extends Object
implements BasicInput

Random-access BasicInput implementation that maps a given region of a file as a monolithic byte buffer. On close, an attempt is made to unmap the buffer.

Note: DO NOT use an instance of this class from multiple threads - see Unmapper.

Since:
1 Dec 2014

Constructor Summary
SimpleMappedInput(FileChannel chan, long pos, int size, String logName)
          Constructor.
 
Method Summary
 void close()
          Releases resources belonging to this object.
 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 pos)
          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
 

Constructor Detail

SimpleMappedInput

public SimpleMappedInput(FileChannel chan,
                         long pos,
                         int size,
                         String logName)
                  throws IOException
Constructor.

Parameters:
chan - file channel, preferably read-only
pos - offset into file of stream start
size - number of bytes in stream
logName - name for mapped region used in logging messages
Throws:
IOException
Method Detail

isRandom

public boolean isRandom()
Description copied from interface: BasicInput
Indicates whether this object supports random access. The seek and getOffset methods may only be called if this method returns true.

Specified by:
isRandom in interface BasicInput
Returns:
true iff random access is supported

seek

public void seek(long pos)
          throws EOFException
Description copied from interface: BasicInput
Moves the current position of this stream to a given byte offset (optional operation).

Specified by:
seek in interface BasicInput
Throws:
EOFException

getOffset

public long getOffset()
Description copied from interface: BasicInput
Returns the curent position in this stream (optional operation).

Specified by:
getOffset in interface BasicInput

skip

public void skip(long nbyte)
          throws IOException
Description copied from interface: BasicInput
Skips a given number of bytes forwards through the stream. An exception is thrown if there are not enough bytes left.

Specified by:
skip in interface BasicInput
Parameters:
nbyte - number of bytes to skip
Throws:
IOException

readByte

public byte readByte()
              throws EOFException
Description copied from interface: BasicInput
Reads a byte from the stream. The current position is advanced.

Specified by:
readByte in interface BasicInput
Returns:
byte value
Throws:
EOFException

readShort

public short readShort()
                throws EOFException
Description copied from interface: BasicInput
Reads a 2-byte integer from the stream. The current position is advanced.

Specified by:
readShort in interface BasicInput
Returns:
short value
Throws:
EOFException

readInt

public int readInt()
            throws EOFException
Description copied from interface: BasicInput
Reads a 4-byte integer from the stream. The current position is advanced.

Specified by:
readInt in interface BasicInput
Returns:
int value
Throws:
EOFException

readLong

public long readLong()
              throws EOFException
Description copied from interface: BasicInput
Reads an 8-byte integer from the stream. The current position is advanced.

Specified by:
readLong in interface BasicInput
Returns:
long value
Throws:
EOFException

readFloat

public float readFloat()
                throws EOFException
Description copied from interface: BasicInput
Reads a 4-byte floating point value from the stream. The current position is advanced.

Specified by:
readFloat in interface BasicInput
Returns:
float value
Throws:
EOFException

readDouble

public double readDouble()
                  throws EOFException
Description copied from interface: BasicInput
Reads an 8-byte floating point value from the stream. The current position is advanced.

Specified by:
readDouble in interface BasicInput
Returns:
double value
Throws:
EOFException

close

public void close()
Description copied from interface: BasicInput
Releases resources belonging to this object. Attempts to use it after a call to this method result in undefined behaviour.

Specified by:
close in interface BasicInput

Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.