Package nom.tam.util

Class OutputEncoder.OutputBuffer

java.lang.Object
nom.tam.util.OutputEncoder.OutputBuffer
Enclosing class:
OutputEncoder

protected final class OutputEncoder.OutputBuffer extends Object

The conversion buffer for encoding Java arrays (objects) into a binary data representation.

The buffering is most efficient if multiple conversions (put methods) are collated before a forced OutputEncoder.flush() call to the output. The caller need not worry about space remaining in the buffer. As new data is placed (put) into the buffer, the buffer will automatically flush the contents to the output to make space for new elements as it goes. The caller only needs to call the final OutputEncoder.flush(), to ensure that all elements bufferes so far are written to the output.

 short[] shortArray = new short[100];
 float[] floaTarray = new float[48];

 // populate the arrays with data...

 // Convert to binary representation using the local
 // conversion buffer.
 ConversionBuffer buf = getBuffer();

 // Convert as much data as we want to the output format...
 buf.putDouble(1.0);
 buf.putInt(-1);
 buf.put(shortArray, 0, shortArray.length);
 buf.put(floatArray, 0, floatArray.length);

 // Once we are done with a chunk of data, we need to
 // make sure all it written to the output
 buf.flush();
 
Author:
Attila Kovacs
  • Method Summary

    Modifier and Type
    Method
    Description
    protected ByteOrder
    Returns the current byte order of the binary representation to which data is encoded.
    protected void
    put(byte[] src, int start, int length)
    Puts an array of bytes into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
    protected void
    put(double[] src, int start, int length)
    Puts an array of 64-bit double-precision floating point values into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
    protected void
    put(float[] src, int start, int length)
    Puts an array of 32-bit single-precision floating point values into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
    protected void
    put(int[] src, int start, int length)
    Puts an array of 32-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
    protected void
    put(long[] src, int start, int length)
    Puts an array of 64-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
    protected void
    put(short[] src, int start, int length)
    Puts an array of 16-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
    protected void
    putByte(byte b)
    Puts a single byte into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
    protected void
    putDouble(double d)
    Puts an 8-byte double-precision floating point value into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
    protected void
    putFloat(float f)
    Puts an 4-byte single-precision floating point value into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
    protected void
    putInt(int i)
    Puts a 4-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
    protected void
    putLong(long l)
    Puts an 8-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
    protected void
    putShort(short s)
    Puts a 2-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
    protected void
    Sets the byte order of the binary representation to which data is encoded.

    Methods inherited from class java.lang.Object

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

    • setByteOrder

      protected void setByteOrder(ByteOrder order)
      Sets the byte order of the binary representation to which data is encoded.
      Parameters:
      order - the new byte order
      See Also:
    • byteOrder

      protected ByteOrder byteOrder()
      Returns the current byte order of the binary representation to which data is encoded.
      Returns:
      the byte order
      See Also:
    • putByte

      protected void putByte(byte b) throws IOException
      Puts a single byte into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
      Parameters:
      b - the byte value
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.
      See Also:
    • putShort

      protected void putShort(short s) throws IOException
      Puts a 2-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
      Parameters:
      s - the 16-bit integer value
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.
      See Also:
    • putInt

      protected void putInt(int i) throws IOException
      Puts a 4-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
      Parameters:
      i - the 32-bit integer value
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.
      See Also:
    • putLong

      protected void putLong(long l) throws IOException
      Puts an 8-byte integer into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
      Parameters:
      l - the 64-bit integer value
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.
      See Also:
    • putFloat

      protected void putFloat(float f) throws IOException
      Puts an 4-byte single-precision floating point value into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
      Parameters:
      f - the 32-bit single-precision floating point value
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.
      See Also:
    • putDouble

      protected void putDouble(double d) throws IOException
      Puts an 8-byte double-precision floating point value into the conversion buffer, making space for it as needed by flushing the current buffer contents to the output as necessary.
      Parameters:
      d - the 64-bit double-precision floating point value
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.
      See Also:
    • put

      protected void put(byte[] src, int start, int length) throws IOException
      Puts an array of bytes into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
      Parameters:
      src - an array of byte values
      start - the index of the first element to convert
      length - the number of elements to convert
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.
    • put

      protected void put(short[] src, int start, int length) throws IOException
      Puts an array of 16-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
      Parameters:
      src - an array of 16-bit integer values
      start - the index of the first element to convert
      length - the number of elements to convert
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.
    • put

      protected void put(int[] src, int start, int length) throws IOException
      Puts an array of 32-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
      Parameters:
      src - an array of 32-bit integer values
      start - the index of the first element to convert
      length - the number of elements to convert
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.
    • put

      protected void put(long[] src, int start, int length) throws IOException
      Puts an array of 64-bit integers into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
      Parameters:
      src - an array of 64-bit integer values
      start - the index of the first element to convert
      length - the number of elements to convert
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.
    • put

      protected void put(float[] src, int start, int length) throws IOException
      Puts an array of 32-bit single-precision floating point values into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
      Parameters:
      src - an array of 32-bit single-precision floating point values
      start - the index of the first element to convert
      length - the number of elements to convert
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.
    • put

      protected void put(double[] src, int start, int length) throws IOException
      Puts an array of 64-bit double-precision floating point values into the conversion buffer, flushing the buffer intermittently as necessary to make room as it goes.
      Parameters:
      src - an array of 64-bit double-precision floating point values
      start - the index of the first element to convert
      length - the number of elements to convert
      Throws:
      IOException - if the conversion buffer could not be flushed to the output to make room for the new conversion.