Package nom.tam.util
Class InputDecoder
java.lang.Object
nom.tam.util.InputDecoder
- Direct Known Subclasses:
FitsDecoder
Efficient base class for decoding of binary input into Java arrays (primarily for internal use)
- Since:
- 1.16
- Author:
- Attila Kovacs
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected final class
The conversion buffer for decoding binary data representation into Java arrays (objects). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Instantiates a new decoder of binary input to Java arrays.Instantiates a new decoder for converting data representations into Java arrays. -
Method Summary
Modifier and TypeMethodDescriptionprotected InputDecoder.InputBuffer
Returns the buffer that is used for conversion, which can be used to bulk read bytes ahead from the input (seeInputDecoder.InputBuffer.loadBytes(long, int)
) andInputDecoder.InputBuffer.loadOne(int)
) before doing conversions to Java types locally.protected int
read()
Reads one byte from the input.protected int
read
(byte[] b, int start, int length) Reads bytes into an array from the input.abstract long
See the contract ofArrayDataInput.readLArray(Object)
.void
Based onreadArray(Object)
, but guaranteeing a complete read of the supplied object or else anEOFException
is thrown.protected void
readFully
(byte[] b, int off, int len) Reads bytes to fill the supplied buffer with the requested number of bytes from the given starting buffer index.void
LikereadArrayFully(Object)
but strictly for numerical types only.protected void
Sets the input from which to read the binary output.
-
Constructor Details
-
InputDecoder
protected InputDecoder()Instantiates a new decoder of binary input to Java arrays. To be used by subclass constructors only.- See Also:
-
InputDecoder
Instantiates a new decoder for converting data representations into Java arrays.- Parameters:
i
- the binary input.
-
-
Method Details
-
setInput
Sets the input from which to read the binary output.- Parameters:
i
- the new binary input.
-
getInputBuffer
Returns the buffer that is used for conversion, which can be used to bulk read bytes ahead from the input (seeInputDecoder.InputBuffer.loadBytes(long, int)
) andInputDecoder.InputBuffer.loadOne(int)
) before doing conversions to Java types locally.- Returns:
- the conversion buffer used by this decoder.
-
read
Reads one byte from the input. See the contract ofInputStream.read()
.- Returns:
- the byte, or -1 if at the end of the file.
- Throws:
IOException
- if an IO error, other than the end-of-file prevented the read.
-
read
Reads bytes into an array from the input. See the contract ofInputStream.read(byte[], int, int)
.- Parameters:
b
- the destination arraystart
- the first index in the array to be populatedlength
- the number of bytes to read into the array.- Returns:
- the number of bytes successfully read, or -1 if at the end of the file.
- Throws:
IOException
- if an IO error, other than the end-of-file prevented the read.
-
readFully
Reads bytes to fill the supplied buffer with the requested number of bytes from the given starting buffer index. If not enough bytes are avaialable in the file to deliver the reqauested number of bytes the buffer, anEOFException
will be thrown.- Parameters:
b
- the bufferoff
- the buffer index at which to start reading datalen
- the total number of bytes to read.- Throws:
EOFException
- if already at the end of file.IOException
- if there was an IO error before the requested number of bytes could all be read.
-
readArrayFully
Based onreadArray(Object)
, but guaranteeing a complete read of the supplied object or else anEOFException
is thrown.- Parameters:
o
- the array, including multi-dimensional, and heterogeneous arrays of arrays.- Throws:
EOFException
- if already at the end of file.IOException
- if there was an IO errorIllegalArgumentException
- if the argument is not a Java array, or is or contains elements that do not have supported conversions from binary representation.- See Also:
-
readArray
See the contract ofArrayDataInput.readLArray(Object)
.- Parameters:
o
- an array, to be populated- Returns:
- the actual number of bytes read from the input, or -1 if already at the end-of-file.
- Throws:
IllegalArgumentException
- if the argument is not an array or if it contains an element that is not supported for decoding.IOException
- if there was an IO error reading from the input- See Also:
-
readImage
LikereadArrayFully(Object)
but strictly for numerical types only.- Parameters:
o
- An any-dimensional array containing only numerical types- Throws:
IllegalArgumentException
- if the argument is not an array or if it contains an element that is not supported.EOFException
- if already at the end of file.IOException
- if there was an IO error- Since:
- 1.18
- See Also:
-