Class TupleOutput

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class TupleOutput extends FastOutputStream
An OutputStream with DataOutput-like methods for writing tuple fields. It is used by TupleBinding.

This class has many methods that have the same signatures as methods in the DataOutput interface. The reason this class does not implement DataOutput is because it would break the interface contract for those methods because of data format differences.

See Also:
  • Constructor Details

    • TupleOutput

      public TupleOutput()
      Creates a tuple output object for writing a byte array of tuple data.
    • TupleOutput

      public TupleOutput(byte[] buffer)
      Creates a tuple output object for writing a byte array of tuple data, using a given buffer. A new buffer will be allocated only if the number of bytes needed is greater than the length of this buffer. A reference to the byte array will be kept by this object and therefore the byte array should not be modified while this object is in use.
      Parameters:
      buffer - is the byte array to use as the buffer.
  • Method Details

    • writeBytes

      public final TupleOutput writeBytes(String val)
      Writes the specified bytes to the buffer, converting each character to an unsigned byte value. Writes values that can be read using TupleInput.readBytes(int).
      Parameters:
      val - is the string containing the values to be written. Only characters with values below 0x100 may be written using this method, since the high-order 8 bits of all characters are discarded.
      Returns:
      this tuple output object.
      Throws:
      NullPointerException - if the val parameter is null.
      See Also:
    • writeChars

      public final TupleOutput writeChars(String val)
      Writes the specified characters to the buffer, converting each character to a two byte unsigned value. Writes values that can be read using TupleInput.readChars(int).
      Parameters:
      val - is the string containing the characters to be written.
      Returns:
      this tuple output object.
      Throws:
      NullPointerException - if the val parameter is null.
      See Also:
    • writeString

      public final TupleOutput writeString(String val)
      Writes the specified characters to the buffer, converting each character to UTF format, and adding a null terminator byte. Writes values that can be read using TupleInput.readString().
      Parameters:
      val - is the string containing the characters to be written.
      Returns:
      this tuple output object.
      See Also:
    • writeChar

      public final TupleOutput writeChar(int val)
      Writes a char (two byte) unsigned value to the buffer. Writes values that can be read using TupleInput.readChar().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeBoolean

      public final TupleOutput writeBoolean(boolean val)
      Writes a boolean (one byte) unsigned value to the buffer, writing one if the value is true and zero if it is false. Writes values that can be read using TupleInput.readBoolean().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeByte

      public final TupleOutput writeByte(int val)
      Writes an signed byte (one byte) value to the buffer. Writes values that can be read using TupleInput.readByte().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeShort

      public final TupleOutput writeShort(int val)
      Writes an signed short (two byte) value to the buffer. Writes values that can be read using TupleInput.readShort().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeInt

      public final TupleOutput writeInt(int val)
      Writes an signed int (four byte) value to the buffer. Writes values that can be read using TupleInput.readInt().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeLong

      public final TupleOutput writeLong(long val)
      Writes an signed long (eight byte) value to the buffer. Writes values that can be read using TupleInput.readLong().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeFloat

      public final TupleOutput writeFloat(float val)
      Writes an unsorted float (four byte) value to the buffer. Writes values that can be read using TupleInput.readFloat().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeDouble

      public final TupleOutput writeDouble(double val)
      Writes an unsorted double (eight byte) value to the buffer. Writes values that can be read using TupleInput.readDouble().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeSortedFloat

      public final TupleOutput writeSortedFloat(float val)
      Writes a sorted float (four byte) value to the buffer. Writes values that can be read using TupleInput.readSortedFloat().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeSortedDouble

      public final TupleOutput writeSortedDouble(double val)
      Writes a sorted double (eight byte) value to the buffer. Writes values that can be read using TupleInput.readSortedDouble().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeBytes

      public final TupleOutput writeBytes(char[] chars)
      Writes the specified bytes to the buffer, converting each character to an unsigned byte value. Writes values that can be read using TupleInput.readBytes(int).
      Parameters:
      chars - is the array of values to be written. Only characters with values below 0x100 may be written using this method, since the high-order 8 bits of all characters are discarded.
      Returns:
      this tuple output object.
      Throws:
      NullPointerException - if the chars parameter is null.
      See Also:
    • writeChars

      public final TupleOutput writeChars(char[] chars)
      Writes the specified characters to the buffer, converting each character to a two byte unsigned value. Writes values that can be read using TupleInput.readChars(int).
      Parameters:
      chars - is the array of characters to be written.
      Returns:
      this tuple output object.
      Throws:
      NullPointerException - if the chars parameter is null.
      See Also:
    • writeString

      public final TupleOutput writeString(char[] chars)
      Writes the specified characters to the buffer, converting each character to UTF format. Writes values that can be read using TupleInput.readString(int) or TupleInput.readString(char[]).
      Parameters:
      chars - is the array of characters to be written.
      Returns:
      this tuple output object.
      Throws:
      NullPointerException - if the chars parameter is null.
      See Also:
    • writeUnsignedByte

      public final TupleOutput writeUnsignedByte(int val)
      Writes an unsigned byte (one byte) value to the buffer. Writes values that can be read using TupleInput.readUnsignedByte().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeUnsignedShort

      public final TupleOutput writeUnsignedShort(int val)
      Writes an unsigned short (two byte) value to the buffer. Writes values that can be read using TupleInput.readUnsignedShort().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writeUnsignedInt

      public final TupleOutput writeUnsignedInt(long val)
      Writes an unsigned int (four byte) value to the buffer. Writes values that can be read using TupleInput.readUnsignedInt().
      Parameters:
      val - is the value to write to the buffer.
      Returns:
      this tuple output object.
      See Also:
    • writePackedInt

      public final TupleOutput writePackedInt(int val)
      Writes an unsorted packed integer.
      See Also:
    • writePackedLong

      public final TupleOutput writePackedLong(long val)
      Writes an unsorted packed long integer.
      See Also:
    • writeSortedPackedInt

      public final TupleOutput writeSortedPackedInt(int val)
      Writes a sorted packed integer.
      See Also:
    • writeSortedPackedLong

      public final TupleOutput writeSortedPackedLong(long val)
      Writes a sorted packed long integer.
      See Also:
    • writeBigInteger

      public final TupleOutput writeBigInteger(BigInteger val)
      Writes a BigInteger.
      Throws:
      NullPointerException - if val is null.
      IllegalArgumentException - if the byte array representation of val is larger than 0x7fff bytes.
      See Also:
    • getBigIntegerByteLength

      public static int getBigIntegerByteLength(BigInteger val)
      Returns the exact byte length that would would be output for a given BigInteger value if writeBigInteger(java.math.BigInteger) were called.
      See Also:
    • writeBigDecimal

      public final TupleOutput writeBigDecimal(BigDecimal val)
      Writes an unsorted BigDecimal.
      Throws:
      NullPointerException - if val is null.
      See Also:
    • getBigDecimalMaxByteLength

      public static int getBigDecimalMaxByteLength(BigDecimal val)
      Returns the maximum byte length that would be output for a given BigDecimal value if writeBigDecimal(java.math.BigDecimal) were called.
      See Also:
    • writeSortedBigDecimal

      public final TupleOutput writeSortedBigDecimal(BigDecimal val)
      Writes a sorted BigDecimal.
      See Also:
    • getSortedBigDecimalMaxByteLength

      public static int getSortedBigDecimalMaxByteLength(BigDecimal val)
      Returns the maximum byte length that would be output for a given BigDecimal value if writeSortedBigDecimal(java.math.BigDecimal) were called.
      See Also: