Class FitsInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.BufferedInputStream
nom.tam.util.ArrayInputStream
nom.tam.util.FitsInputStream
- All Implemented Interfaces:
Closeable, DataInput, AutoCloseable, ArrayDataInput, FitsIO, InputReader
- Direct Known Subclasses:
BufferedDataInputStream
For reading FITS files through an
InputStream.
Testing and timing routines are provided in the nom.tam.util.test.BufferedFileTester class.
Prior versions under the old BufferedDataInputStream:
- Version 1.1 -- October 12, 2000: Fixed handling of EOF to return partially read arrays when EOF is detected
- Version 1.2 -- July 20, 2009: Added handling of very large Object arrays. Additional work is required to handle very large arrays generally.
Version 2.0 -- October 30, 2021: Completely overhauled, with new name and hierarchy. Performance is 2-4 times better than before (Attila Kovacs)
- See Also:
-
Field Summary
Fields inherited from interface FitsIO
BITS_OF_1_BYTE, BITS_OF_2_BYTES, BITS_OF_3_BYTES, BITS_OF_4_BYTES, BITS_OF_5_BYTES, BITS_OF_6_BYTES, BITS_OF_7_BYTES, BYTE_1_OF_LONG_MASK, BYTE_2_OF_LONG_MASK, BYTE_3_OF_LONG_MASK, BYTE_4_OF_LONG_MASK, BYTE_MASK, BYTES_IN_BOOLEAN, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_DOUBLE, BYTES_IN_FLOAT, BYTES_IN_INTEGER, BYTES_IN_LONG, BYTES_IN_SHORT, DEFAULT_BUFFER_SIZE, HIGH_INTEGER_MASK, INTEGER_MASK, SHORT_MASK, SHORT_OF_LONG_MASKModifier and TypeFieldDescriptionstatic final intnumber of bits in one byte.static final intnumber of bits in two byte.static final intnumber of bits in three byte.static final intnumber of bits in four byte.static final intnumber of bits in five byte.static final intnumber of bits in six byte.static final intnumber of bits in seven byte.static final longbit mask to get the lowest byte of a long.static final longbit mask to get the second lowest byte of a long.static final longbit mask to get the third lowest byte of a long.static final longbit mask to get the fourth lowest byte of a long.static final intbit mask to get the lowest byte from an integer.static final intnumber of bytes occupied by a boolean.static final intnumber of bytes occupied by a byte.static final intnumber of bytes occupied by a char.static final intnumber of bytes occupied by a double.static final intnumber of bytes occupied by a float.static final intnumber of bytes occupied by a integer.static final intnumber of bytes occupied by a long.static final intnumber of bytes occupied by a short.static final intdefault buffer size to use unless specified otherwise.static final longbit mask to get the highest integer from an long.static final longbit mask to get the lowest integer from an long.static final intbit mask to get the lowest short of a integer.static final longbit mask to get the lowest short of a long. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a BufferedInputStream based on an input stream.FitsInputStream(InputStream i, int bufLength) Create a BufferedInputStream based on a input stream with a specified buffer size. -
Method Summary
Modifier and TypeMethodDescriptionfinal long(for internal use) Returns the aggregated checksum for this stream since the last call to this method, or else since instantiation.intread()Reads a byte.intread(boolean[] b, int start, int length) Read a segment of an array of boolean's.intread(byte[] b, int from, int len) Reads up to the specified number of bytes into a buffer.intread(char[] c, int start, int length) Read a segment of an array of char's.intread(double[] d, int start, int length) Read a segment of an array of double's.intread(float[] f, int start, int length) Read a segment of an array of float's.intread(int[] i, int start, int length) Read a segment of an array of int's.intread(long[] l, int start, int length) Read a segment of an array of long's.intread(short[] s, int start, int length) Read a segment of an array of short's.intReads into an array of booleans, possibly including legalnullvalues.booleanbytereadByte()charreadChar()doublefloatvoidreadFully(byte[] b) voidreadFully(byte[] b, int off, int len) intreadInt()final StringreadLine()longreadLong()final intDeprecated.shortintintreadUTF()longskip(long n) Skip the number of bytes.voidskipAllBytes(long toSkip) Skips a number of bytes from the input.intskipBytes(int n) toString()Methods inherited from class ArrayInputStream
readArrayFully, readImage, readLArrayModifier and TypeMethodDescriptionvoidSeeArrayDataInput.readArrayFully(Object)for a contract of this method.voidLikeArrayInputStream.readArrayFully(Object)but strictly for numerical types only.longreadLArray(Object o) SeeArrayDataInput.readLArray(Object)for a contract of this method.Methods inherited from class BufferedInputStream
available, close, mark, markSupported, reset, transferToMethods inherited from class FilterInputStream
readMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytesMethods inherited from interface ArrayDataInput
mark, markSupported, read, read, read, read, read, read, read, read, read, readArray, readArrayFully, readImage, readLArray, reset, skipAllBytesModifier and TypeMethodDescriptionvoidmark(int readlimit) See the general contract of themarkmethod ofInputStream.default booleanSee the general contract of themarkSupportedmethod ofInputStream.default intread(boolean[] buf) Read an array of boolean's.intread(byte[] buf) Read an array of byte's.default intread(char[] buf) Read an array of char's.default intread(double[] buf) Read an array of double's.default intread(float[] buf) Read an array of float's.default intread(int[] buf) Read an array of int's.default intread(long[] buf) Read a segment of an array of long's.default intread(short[] buf) Read an array of short's.default intRead an array of booleans, possibly including legalnullvalues.default intDeprecated.UseArrayDataInput.readLArray(Object)instead.default voidReads a Java array from the input, populating all elements, or else throwing andEOFException.default voidLikeArrayDataInput.readArrayFully(Object)but strictly for numerical types only.longreadLArray(Object o) Reads a Java array from the input, translating it from its binary representation to Java data format.voidreset()See the general contract of theresetmethod ofInputStream.default voidskipAllBytes(int toSkip) Deprecated.This call is handled byArrayDataInput.skipAllBytes(long), without the need for a separate implementation.
-
Constructor Details
-
FitsInputStream
Create a BufferedInputStream based on a input stream with a specified buffer size.- Parameters:
i- the input stream to use for reading.bufLength- the buffer length to use.
-
FitsInputStream
Create a BufferedInputStream based on an input stream.- Parameters:
i- the input stream to use for reading.
-
-
Method Details
-
read
Description copied from interface:InputReaderReads a byte. See the general contract ofFilterInputStream.read().- Specified by:
readin interfaceInputReader- Overrides:
readin classBufferedInputStream- Returns:
- the (unsigned) byte value or -1 if there is nothing left to read.
- Throws:
IOException- if there was an underlying IO error- See Also:
-
read
Description copied from interface:InputReaderReads up to the specified number of bytes into a buffer. See the general contract ofDataInputStream.read(byte[], int, int).- Specified by:
readin interfaceInputReader- Overrides:
readin classBufferedInputStream- Parameters:
b- the bufferfrom- the starting buffer indexlen- the number of bytes to read.- Returns:
- the number of bytes actually read, or -1 if there is nothing left to read.
- Throws:
IOException- if there was an underlying IO error- See Also:
-
nextChecksum
public final long nextChecksum()(for internal use) Returns the aggregated checksum for this stream since the last call to this method, or else since instantiation. Checksums for a block of data thus may be obtained by calling this method both before and after reading the data block -- the first call resets the checksum and the block checksum is returned on the second call. The checksummed block must be a multiple of 2880 bytes (the FITS block size) for the result to be valid.- Returns:
- the aggregated checksum since the last call to this method, or else since instantiation, on an integer number of FITS blocks read in the meantime.
- Since:
- 1.18.1
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceArrayDataInput- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
read
Description copied from interface:ArrayDataInputRead a segment of an array of boolean's.- Specified by:
readin interfaceArrayDataInput- Parameters:
b- array of boolean's.start- start index in the arraylength- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInputReads into an array of booleans, possibly including legalnullvalues. The method has a default implementation, callsDataInput.readBoolean()element by element. Classes that implement this interface might want to replace that with a more efficient block read implementation and/or to add the desired translation fornullvalues.- Specified by:
readin interfaceArrayDataInput- Parameters:
b- array of boolean's.start- start index in the arraylength- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInputRead a segment of an array of char's.- Specified by:
readin interfaceArrayDataInput- Parameters:
c- array of char's.start- start index in the arraylength- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInputRead a segment of an array of short's.- Specified by:
readin interfaceArrayDataInput- Parameters:
s- array of short's.start- start index in the arraylength- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInputRead a segment of an array of int's.- Specified by:
readin interfaceArrayDataInput- Parameters:
i- array of int's.start- start index in the arraylength- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInputRead a segment of an array of long's.- Specified by:
readin interfaceArrayDataInput- Parameters:
l- array of long's.start- start index in the arraylength- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInputRead a segment of an array of float's.- Specified by:
readin interfaceArrayDataInput- Parameters:
f- array of float's.start- start index in the arraylength- number of array elements to read- Returns:
- number of bytes read.
- Throws:
IOException- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInputRead a segment of an array of double's.- Specified by:
readin interfaceArrayDataInput- Parameters:
d- array of double's.start- start index in the arraylength- number of array elements to read- Returns:
- number of bytes read, or -1 if at the end of file/stream
- Throws:
IOException- if one of the underlying read operations failed
-
readPrimitiveArray
Deprecated.useArrayInputStream.readLArray(Object)insteadThis routine provides efficient reading of arrays of any primitive type. It is an error to invoke this method with an object that is not an array of some primitive type. Note that there is no corresponding capability to writePrimitiveArray in BufferedDataOutputStream to read in an array of Strings.- Parameters:
o- The object to be read. It must be an array of a primitive type, or an array of Object's.- Returns:
- number of bytes read.
- Throws:
IOException- if the underlying read operation fails
-
skip
Description copied from interface:ArrayDataInputSkip the number of bytes. This differs from the skip method in that it will throw an EOF if a forward skip cannot be fully accomplished... (However that isn't supposed to happen with a random access file, so there is probably no operational difference).- Specified by:
skipin interfaceArrayDataInput- Overrides:
skipin classBufferedInputStream- Parameters:
n- the number of bytes to skip. Negative arguments are generally allowed, and subclass implementations may support it or else return 0 when a negative distance is specified.- Returns:
- the number of bytes actually skipped
- Throws:
IOException- if the underlying stream failed- See Also:
-
skipBytes
- Specified by:
skipBytesin interfaceDataInput- Throws:
IOException
-
skipAllBytes
Description copied from interface:ArrayDataInputSkips a number of bytes from the input. This differs from theArrayDataInput.skip(long)method in that it will throw an EOF if the skip cannot be fully accomplished as requested...- Specified by:
skipAllBytesin interfaceArrayDataInput- Parameters:
toSkip- the number of bytes to skip forward. Subclass implementations may support negative valued arguments for a backward skip also.- Throws:
EOFException- if the end (or beginning) of the stream was reached before skipping the required number of bytes. This does not happen typically with forward skips on random access files, where positioning beyond the EOF is generally allowed for writing.IOException- if there was an underlying IO failure.- See Also:
-
readBoolean
- Specified by:
readBooleanin interfaceDataInput- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedBytein interfaceDataInput- Throws:
IOException
-
readByte
- Specified by:
readBytein interfaceDataInput- Throws:
IOException
-
readChar
- Specified by:
readCharin interfaceDataInput- Throws:
IOException
-
readUnsignedShort
- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
IOException
-
readShort
- Specified by:
readShortin interfaceDataInput- Throws:
IOException
-
readInt
- Specified by:
readIntin interfaceDataInput- Throws:
IOException
-
readLong
- Specified by:
readLongin interfaceDataInput- Throws:
IOException
-
readFloat
- Specified by:
readFloatin interfaceDataInput- Throws:
IOException
-
readDouble
- Specified by:
readDoublein interfaceDataInput- Throws:
IOException
-
readUTF
- Specified by:
readUTFin interfaceDataInput- Throws:
IOException
-
readLine
- Specified by:
readLinein interfaceDataInput- Throws:
IOException
-
toString
-
ArrayInputStream.readLArray(Object)instead