Package nom.tam.util

Class OutputEncoder

java.lang.Object
nom.tam.util.OutputEncoder
Direct Known Subclasses:
FitsEncoder

public abstract class OutputEncoder extends Object
Efficient base class for encoding Java arrays into binary output (primarily for internal use)
Since:
1.16
Author:
Attila Kovacs
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected final class 
    The conversion buffer for encoding Java arrays (objects) into a binary data representation.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected OutputWriter
    The output to which to write encoded data (directly or from the conversion buffer)
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Instantiates a new Java-to-binary encoder for arrays.
     
    Instantiates a new Java-to-binary encoder for arrays, writing encoded data to the specified output.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Flushes the contents of the conversion buffer to the underlying output.
    long
    Returns the number of encoded bytes that were written to the output.
    Returns the buffer that is used for conversion, which can be used to collate more elements for writing before bulk flushing data to the output (see flush()).
    protected void
    Sets the output to which encoded data should be written (directly or from the conversion buffer).
    protected void
    write(byte[] b, int start, int length)
    Writes up to the specified number of bytes from a buffer directly to the output.
    protected void
    write(int b)
    Writes a byte directly to the output.
    abstract void
    Writes the contents of a Java array to the output translating the data to the required binary representation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • out

      protected OutputWriter out
      The output to which to write encoded data (directly or from the conversion buffer)
  • Constructor Details

    • OutputEncoder

      protected OutputEncoder()
      Instantiates a new Java-to-binary encoder for arrays. To be used by subclass implementations only
      See Also:
    • OutputEncoder

      public OutputEncoder(OutputWriter o)
      Instantiates a new Java-to-binary encoder for arrays, writing encoded data to the specified output.
      Parameters:
      o - the output to which encoded data is to be written.
  • Method Details

    • setOutput

      protected void setOutput(OutputWriter o)
      Sets the output to which encoded data should be written (directly or from the conversion buffer).
      Parameters:
      o - the new output to which encoded data is to be written.
    • getCount

      public long getCount()
      Returns the number of encoded bytes that were written to the output. It does not include bytes written directly (unencoded) to the output, such as via write(int) or write(byte[], int, int).
      Returns:
      the number of encoded bytes written to the output.
      See Also:
    • getOutputBuffer

      protected OutputEncoder.OutputBuffer getOutputBuffer()
      Returns the buffer that is used for conversion, which can be used to collate more elements for writing before bulk flushing data to the output (see flush()).
      Returns:
      the conversion buffer used by this encoder.
    • flush

      protected void flush() throws IOException
      Flushes the contents of the conversion buffer to the underlying output.
      Throws:
      IOException - if there was an IO error writing the contents of this buffer to the output.
    • write

      protected void write(int b) throws IOException
      Writes a byte directly to the output. See the general contract of DataOutputStream.write(int). Unencoded bytes written by this method are not reflected in the value returned by getCount().
      Parameters:
      b - the (unsigned) byte value to write.
      Throws:
      IOException - if there was an underlying IO error
      See Also:
    • write

      protected void write(byte[] b, int start, int length) throws IOException
      Writes up to the specified number of bytes from a buffer directly to the output. See the general contract of DataOutputStream.write(byte[], int, int). The number of unencoded bytes written by this method are not reflected in the value returned by getCount().
      Parameters:
      b - the buffer
      start - the starting buffer index
      length - the number of bytes to write.
      Throws:
      IOException - if there was an underlying IO error
      See Also:
    • writeArray

      public abstract void writeArray(Object o) throws IOException, IllegalArgumentException
      Writes the contents of a Java array to the output translating the data to the required binary representation. The argument may be any generic Java array, including heterogeneous arrays of arrays.
      Parameters:
      o - the Java array, including heterogeneous arrays of arrays. If null nothing will be written to the output.
      Throws:
      IOException - if there was an IO error writing to the output
      IllegalArgumentException - if the supplied object is not a Java array or if it contains Java types that are not supported by the decoder.
      See Also: