Package uk.ac.starlink.fits
Class SimpleMappedInput
- java.lang.Object
-
- uk.ac.starlink.fits.SimpleMappedInput
-
- All Implemented Interfaces:
BasicInput
public class SimpleMappedInput extends java.lang.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
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Constructor Description SimpleMappedInput(java.nio.channels.FileChannel chan, long pos, int size, java.lang.String logName)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
readBytes(byte[] bbuf)
Reads bytes into an array 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.
-
-
-
Constructor Detail
-
SimpleMappedInput
public SimpleMappedInput(java.nio.channels.FileChannel chan, long pos, int size, java.lang.String logName) throws java.io.IOException
Constructor.- Parameters:
chan
- file channel, preferably read-onlypos
- offset into file of stream startsize
- number of bytes in streamlogName
- name for mapped region used in logging messages- Throws:
java.io.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 interfaceBasicInput
- Returns:
- true iff random access is supported
-
seek
public void seek(long pos) throws java.io.EOFException
Description copied from interface:BasicInput
Moves the current position of this stream to a given byte offset (optional operation).- Specified by:
seek
in interfaceBasicInput
- Throws:
java.io.EOFException
-
getOffset
public long getOffset()
Description copied from interface:BasicInput
Returns the curent position in this stream (optional operation).- Specified by:
getOffset
in interfaceBasicInput
-
skip
public void skip(long nbyte) throws java.io.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 interfaceBasicInput
- Parameters:
nbyte
- number of bytes to skip- Throws:
java.io.IOException
-
readByte
public byte readByte() throws java.io.EOFException
Description copied from interface:BasicInput
Reads a byte from the stream. The current position is advanced.- Specified by:
readByte
in interfaceBasicInput
- Returns:
- byte value
- Throws:
java.io.EOFException
-
readShort
public short readShort() throws java.io.EOFException
Description copied from interface:BasicInput
Reads a 2-byte integer from the stream. The current position is advanced.- Specified by:
readShort
in interfaceBasicInput
- Returns:
- short value
- Throws:
java.io.EOFException
-
readInt
public int readInt() throws java.io.EOFException
Description copied from interface:BasicInput
Reads a 4-byte integer from the stream. The current position is advanced.- Specified by:
readInt
in interfaceBasicInput
- Returns:
- int value
- Throws:
java.io.EOFException
-
readLong
public long readLong() throws java.io.EOFException
Description copied from interface:BasicInput
Reads an 8-byte integer from the stream. The current position is advanced.- Specified by:
readLong
in interfaceBasicInput
- Returns:
- long value
- Throws:
java.io.EOFException
-
readFloat
public float readFloat() throws java.io.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 interfaceBasicInput
- Returns:
- float value
- Throws:
java.io.EOFException
-
readDouble
public double readDouble() throws java.io.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 interfaceBasicInput
- Returns:
- double value
- Throws:
java.io.EOFException
-
readBytes
public void readBytes(byte[] bbuf) throws java.io.EOFException
Description copied from interface:BasicInput
Reads bytes into an array from the stream. The current position is advanced.- Specified by:
readBytes
in interfaceBasicInput
- Parameters:
bbuf
- array into which the bytes are read; the number of bytes read is the length of the array- Throws:
java.io.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 interfaceBasicInput
-
-