Package nom.tam.util

Class InputDecoder

java.lang.Object
nom.tam.util.InputDecoder
Direct Known Subclasses:
FitsDecoder

public abstract class InputDecoder extends Object
Efficient base class for decoding of binary input into Java arrays (primarily for internal use)
Since:
1.16
Author:
Attila Kovacs
See Also:
  • 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

      public InputDecoder(InputReader i)
      Instantiates a new decoder for converting data representations into Java arrays.
      Parameters:
      i - the binary input.
  • Method Details

    • setInput

      protected void setInput(InputReader i)
      Sets the input from which to read the binary output.
      Parameters:
      i - the new binary input.
    • getInputBuffer

      protected InputDecoder.InputBuffer getInputBuffer()
      Returns the buffer that is used for conversion, which can be used to bulk read bytes ahead from the input (see InputDecoder.InputBuffer.loadBytes(long, int)) and InputDecoder.InputBuffer.loadOne(int)) before doing conversions to Java types locally.
      Returns:
      the conversion buffer used by this decoder.
    • read

      protected int read() throws IOException
      Reads one byte from the input. See the contract of InputStream.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

      protected int read(byte[] b, int start, int length) throws IOException
      Reads bytes into an array from the input. See the contract of InputStream.read(byte[], int, int).
      Parameters:
      b - the destination array
      start - the first index in the array to be populated
      length - 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

      protected void readFully(byte[] b, int off, int len) throws EOFException, IOException
      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, an EOFException will be thrown.
      Parameters:
      b - the buffer
      off - the buffer index at which to start reading data
      len - 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

      public void readArrayFully(Object o) throws IOException, IllegalArgumentException
      Based on readArray(Object), but guaranteeing a complete read of the supplied object or else an EOFException 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 error
      IllegalArgumentException - 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

      public abstract long readArray(Object o) throws IOException, IllegalArgumentException
      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

      public void readImage(Object o) throws IOException, IllegalArgumentException
      Like readArrayFully(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: