Package nom.tam.util
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 nom.tam.util.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_MASK
-
Constructor Summary
ConstructorDescriptionCreate 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.int
read()
Reads a byte.int
read
(boolean[] b, int start, int length) Read a segment of an array of boolean's.int
read
(byte[] b, int from, int len) Reads up to the specified number of bytes into a buffer.int
read
(char[] c, int start, int length) Read a segment of an array of char's.int
read
(double[] d, int start, int length) Read a segment of an array of double's.int
read
(float[] f, int start, int length) Read a segment of an array of float's.int
read
(int[] i, int start, int length) Read a segment of an array of int's.int
read
(long[] l, int start, int length) Read a segment of an array of long's.int
read
(short[] s, int start, int length) Read a segment of an array of short's.int
Reads into an array of booleans, possibly including legalnull
values.boolean
byte
readByte()
char
readChar()
double
float
void
readFully
(byte[] b) void
readFully
(byte[] b, int off, int len) int
readInt()
final String
readLine()
long
readLong()
final int
Deprecated.short
int
int
readUTF()
long
skip
(long n) Skip the number of bytes.void
skipAllBytes
(long toSkip) Skips a number of bytes from the input.int
skipBytes
(int n) toString()
Methods inherited from class nom.tam.util.ArrayInputStream
readArrayFully, readImage, readLArray
Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported, reset
Methods inherited from class java.io.FilterInputStream
read
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface nom.tam.util.ArrayDataInput
mark, markSupported, read, read, read, read, read, read, read, read, read, readArray, readArrayFully, readImage, readLArray, reset, skipAllBytes
-
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:InputReader
Reads a byte. See the general contract ofFilterInputStream.read()
.- Specified by:
read
in interfaceInputReader
- Overrides:
read
in 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:InputReader
Reads up to the specified number of bytes into a buffer. See the general contract ofDataInputStream.read(byte[], int, int)
.- Specified by:
read
in interfaceInputReader
- Overrides:
read
in 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:
readFully
in interfaceDataInput
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceArrayDataInput
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of boolean's.- Specified by:
read
in 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:
EOFException
- if already at the end of file.IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Reads into an array of booleans, possibly including legalnull
values. 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 fornull
values.- Specified by:
read
in 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:
EOFException
- if already at the end of file.IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of char's.- Specified by:
read
in 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:
EOFException
- if already at the end of file.IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of short's.- Specified by:
read
in 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:
EOFException
- if already at the end of file.IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of int's.- Specified by:
read
in 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:
EOFException
- if already at the end of file.IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of long's.- Specified by:
read
in 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:
EOFException
- if already at the end of file.IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of float's.- Specified by:
read
in 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:
EOFException
- if already at the end of file.IOException
- if one of the underlying read operations failed
-
read
Description copied from interface:ArrayDataInput
Read a segment of an array of double's.- Specified by:
read
in 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:
EOFException
- if already at the end of file.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:ArrayDataInput
Skip 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:
skip
in interfaceArrayDataInput
- Overrides:
skip
in 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:
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 the underlying stream failed- See Also:
-
skipBytes
- Specified by:
skipBytes
in interfaceDataInput
- Throws:
IOException
-
skipAllBytes
Description copied from interface:ArrayDataInput
Skips 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:
skipAllBytes
in 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:
readBoolean
in interfaceDataInput
- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedByte
in interfaceDataInput
- Throws:
IOException
-
readByte
- Specified by:
readByte
in interfaceDataInput
- Throws:
IOException
-
readChar
- Specified by:
readChar
in interfaceDataInput
- Throws:
IOException
-
readUnsignedShort
- Specified by:
readUnsignedShort
in interfaceDataInput
- Throws:
IOException
-
readShort
- Specified by:
readShort
in interfaceDataInput
- Throws:
IOException
-
readInt
- Specified by:
readInt
in interfaceDataInput
- Throws:
IOException
-
readLong
- Specified by:
readLong
in interfaceDataInput
- Throws:
IOException
-
readFloat
- Specified by:
readFloat
in interfaceDataInput
- Throws:
IOException
-
readDouble
- Specified by:
readDouble
in interfaceDataInput
- Throws:
IOException
-
readUTF
- Specified by:
readUTF
in interfaceDataInput
- Throws:
IOException
-
readLine
- Specified by:
readLine
in interfaceDataInput
- Throws:
IOException
-
toString
-
ArrayInputStream.readLArray(Object)
instead