Package uk.ac.starlink.fits
Class BufferedRandomInput
java.lang.Object
uk.ac.starlink.fits.BufferedRandomInput
- All Implemented Interfaces:
BasicInput
BasicInput implementation based on a RandomAccessFile.
Buffering of the underlying file is performed on the assumption that
access will be largely sequential.
- Since:
- 8 Nov 2017
- Author:
- Mark Taylor
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBufferedRandomInput
(RandomAccessFile file, long offset0) Constructs a BufferedRandomInput with a default sized buffer.BufferedRandomInput
(RandomAccessFile file, long offset0, int bufsize) Constructs a BufferedRandomInput with a buffer of specified size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Releases resources belonging to this object.long
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
Reads an 8-byte floating point value from the stream.float
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
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 nbytes) Skips a given number of bytes forwards through the stream.
-
Field Details
-
DFLT_BUFSIZE
public static final int DFLT_BUFSIZE
-
-
Constructor Details
-
BufferedRandomInput
Constructs a BufferedRandomInput with a default sized buffer.- Parameters:
file
- fileoffset0
- offset into file of stream start- Throws:
IOException
-
BufferedRandomInput
Constructs a BufferedRandomInput with a buffer of specified size.- Parameters:
file
- fileoffset0
- offset into file of stream startbufsize
- buffer size- Throws:
IOException
-
-
Method Details
-
readByte
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:
IOException
-
readShort
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:
IOException
-
readInt
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:
IOException
-
readLong
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:
IOException
-
readFloat
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:
IOException
-
readDouble
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:
IOException
-
readBytes
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:
IOException
-
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
-
skip
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:
nbytes
- number of bytes to skip- Throws:
IOException
-
getOffset
public long getOffset()Description copied from interface:BasicInput
Returns the curent position in this stream (optional operation).- Specified by:
getOffset
in interfaceBasicInput
-
seek
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:
IOException
-
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
- Throws:
IOException
-