com.sleepycat.bind.tuple

## Class TupleInput

- java.lang.Object
- - java.io.InputStream
  - - com.sleepycat.util.FastInputStream
    - - com.sleepycat.bind.tuple.TupleInput

All Implemented Interfaces:
  java.io.Closeable, java.lang.AutoCloseable

    public class TupleInput
    extends FastInputStream

An `InputStream` with `DataInput`-like methods for reading tuple fields. It is used by `TupleBinding`.

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

See Also:
  Tuple Formats

### Field Summary

### Fields inherited from class com.sleepycat.util.FastInputStream

`buf, len, mark, off`

### Constructor Summary

Constructors
Constructor and Description
`TupleInput(byte[] buffer)` Creates a tuple input object for reading a byte array of tuple data.
`TupleInput(byte[] buffer, int offset, int length)` Creates a tuple input object for reading a byte array of tuple data at a given offset for a given length.
`TupleInput(TupleOutput output)` Creates a tuple input object from the data contained in a tuple output object.

### Method Summary

All Methods Instance Methods Concrete Methods
`int` `getBigDecimalByteLength()` Returns the byte length of an unsorted `BigDecimal`.
`int` `getBigIntegerByteLength()` Returns the byte length of a `BigInteger`.
`int` `getPackedIntByteLength()` Returns the byte length of a packed integer.
`int` `getPackedLongByteLength()` Returns the byte length of a packed long integer.
`int` `getSortedBigDecimalByteLength()` Returns the byte length of a sorted `BigDecimal`.
`int` `getSortedPackedIntByteLength()` Returns the byte length of a sorted packed integer.
`int` `getSortedPackedLongByteLength()` Returns the byte length of a sorted packed long integer.
`int` `getStringByteLength()` Returns the byte length of a null-terminated UTF string in the data buffer, including the terminator.
`java.math.BigDecimal` `readBigDecimal()` Reads an unsorted `BigDecimal`.
`java.math.BigInteger` `readBigInteger()` Reads a `BigInteger`.
`boolean` `readBoolean()` Reads a boolean (one byte) unsigned value from the buffer and returns true if it is non-zero and false if it is zero.
`byte` `readByte()` Reads a signed byte (one byte) value from the buffer.
`void` `readBytes(char[] chars)` Reads the specified number of bytes from the buffer, converting each unsigned byte value to a character of the resulting array.
`java.lang.String` `readBytes(int length)` Reads the specified number of bytes from the buffer, converting each unsigned byte value to a character of the resulting string.
`char` `readChar()` Reads a char (two byte) unsigned value from the buffer.
`void` `readChars(char[] chars)` Reads the specified number of characters from the buffer, converting each two byte unsigned value to a character of the resulting array.
`java.lang.String` `readChars(int length)` Reads the specified number of characters from the buffer, converting each two byte unsigned value to a character of the resulting string.
`double` `readDouble()` Reads an unsorted double (eight byte) value from the buffer.
`float` `readFloat()` Reads an unsorted float (four byte) value from the buffer.
`int` `readInt()` Reads a signed int (four byte) value from the buffer.
`long` `readLong()` Reads a signed long (eight byte) value from the buffer.
`int` `readPackedInt()` Reads an unsorted packed integer.
`long` `readPackedLong()` Reads an unsorted packed long integer.
`short` `readShort()` Reads a signed short (two byte) value from the buffer.
`java.math.BigDecimal` `readSortedBigDecimal()` Reads a sorted `BigDecimal`, with support for correct default sorting.
`double` `readSortedDouble()` Reads a sorted double (eight byte) value from the buffer.
`float` `readSortedFloat()` Reads a sorted float (four byte) value from the buffer.
`int` `readSortedPackedInt()` Reads a sorted packed integer.
`long` `readSortedPackedLong()` Reads a sorted packed long integer.
`java.lang.String` `readString()` Reads a null-terminated UTF string from the data buffer and converts the data from UTF to Unicode.
`void` `readString(char[] chars)` Reads the specified number of UTF characters string from the data buffer and converts the data from UTF to Unicode.
`java.lang.String` `readString(int length)` Reads the specified number of UTF characters string from the data buffer and converts the data from UTF to Unicode.
`int` `readUnsignedByte()` Reads an unsigned byte (one byte) value from the buffer.
`long` `readUnsignedInt()` Reads an unsigned int (four byte) value from the buffer.
`int` `readUnsignedShort()` Reads an unsigned short (two byte) value from the buffer.

### Methods inherited from class com.sleepycat.util.FastInputStream

`available, getBufferBytes, getBufferLength, getBufferOffset, mark, markSupported, read, read, read, readFast, readFast, readFast, reset, skip, skipFast`

### Methods inherited from class java.io.InputStream

`close`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### TupleInput

    public TupleInput(byte[] buffer)

Creates a tuple input object for reading a byte array of tuple data. A reference to the byte array will be kept by this object (it will not be copied) and therefore the byte array should not be modified while this object is in use.

Parameters:
  `buffer` - is the byte array to be read and should contain data in tuple format.

#### TupleInput

    public TupleInput(byte[] buffer,
                      int offset,
                      int length)

Creates a tuple input object for reading a byte array of tuple data at a given offset for a given length. A reference to the byte array will be kept by this object (it will not be copied) and therefore the byte array should not be modified while this object is in use.

Parameters:
  `buffer` - is the byte array to be read and should contain data in tuple format.
  `offset` - is the byte offset at which to begin reading.
  `length` - is the number of bytes to be read.

#### TupleInput

    public TupleInput(TupleOutput output)

Creates a tuple input object from the data contained in a tuple output object. A reference to the tuple output's byte array will be kept by this object (it will not be copied) and therefore the tuple output object should not be modified while this object is in use.

Parameters:
  `output` - is the tuple output object containing the data to be read.

### Method Detail

#### readString

    public final java.lang.String readString()
                                      throws java.lang.IndexOutOfBoundsException,
                                             java.lang.IllegalArgumentException

Reads a null-terminated UTF string from the data buffer and converts the data from UTF to Unicode. Reads values that were written using `TupleOutput.writeString(String)`.

Returns:
  the converted string.
Throws:
  `java.lang.IndexOutOfBoundsException` - if no null terminating byte is found in the buffer.
  `java.lang.IllegalArgumentException` - malformed UTF data is encountered.
See Also:
  String Formats

#### readChar

    public final char readChar()
                        throws java.lang.IndexOutOfBoundsException

Reads a char (two byte) unsigned value from the buffer. Reads values that were written using `TupleOutput.writeChar(int)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readBoolean

    public final boolean readBoolean()
                              throws java.lang.IndexOutOfBoundsException

Reads a boolean (one byte) unsigned value from the buffer and returns true if it is non-zero and false if it is zero. Reads values that were written using `TupleOutput.writeBoolean(boolean)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readByte

    public final byte readByte()
                        throws java.lang.IndexOutOfBoundsException

Reads a signed byte (one byte) value from the buffer. Reads values that were written using `TupleOutput.writeByte(int)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readShort

    public final short readShort()
                          throws java.lang.IndexOutOfBoundsException

Reads a signed short (two byte) value from the buffer. Reads values that were written using `TupleOutput.writeShort(int)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readInt

    public final int readInt()
                      throws java.lang.IndexOutOfBoundsException

Reads a signed int (four byte) value from the buffer. Reads values that were written using `TupleOutput.writeInt(int)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readLong

    public final long readLong()
                        throws java.lang.IndexOutOfBoundsException

Reads a signed long (eight byte) value from the buffer. Reads values that were written using `TupleOutput.writeLong(long)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readFloat

    public final float readFloat()
                          throws java.lang.IndexOutOfBoundsException

Reads an unsorted float (four byte) value from the buffer. Reads values that were written using `TupleOutput.writeFloat(float)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Floating Point Formats

#### readDouble

    public final double readDouble()
                            throws java.lang.IndexOutOfBoundsException

Reads an unsorted double (eight byte) value from the buffer. Reads values that were written using `TupleOutput.writeDouble(double)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Floating Point Formats

#### readSortedFloat

    public final float readSortedFloat()
                                throws java.lang.IndexOutOfBoundsException

Reads a sorted float (four byte) value from the buffer. Reads values that were written using `TupleOutput.writeSortedFloat(float)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Floating Point Formats

#### readSortedDouble

    public final double readSortedDouble()
                                  throws java.lang.IndexOutOfBoundsException

Reads a sorted double (eight byte) value from the buffer. Reads values that were written using `TupleOutput.writeSortedDouble(double)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Floating Point Formats

#### readUnsignedByte

    public final int readUnsignedByte()
                               throws java.lang.IndexOutOfBoundsException

Reads an unsigned byte (one byte) value from the buffer. Reads values that were written using `TupleOutput.writeUnsignedByte(int)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readUnsignedShort

    public final int readUnsignedShort()
                                throws java.lang.IndexOutOfBoundsException

Reads an unsigned short (two byte) value from the buffer. Reads values that were written using `TupleOutput.writeUnsignedShort(int)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readUnsignedInt

    public final long readUnsignedInt()
                               throws java.lang.IndexOutOfBoundsException

Reads an unsigned int (four byte) value from the buffer. Reads values that were written using `TupleOutput.writeUnsignedInt(long)`.

Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readBytes

    public final java.lang.String readBytes(int length)
                                     throws java.lang.IndexOutOfBoundsException

Reads the specified number of bytes from the buffer, converting each unsigned byte value to a character of the resulting string. Reads values that were written using `TupleOutput.writeBytes(java.lang.String)`.

Parameters:
  `length` - is the number of bytes to be read.
Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readChars

    public final java.lang.String readChars(int length)
                                     throws java.lang.IndexOutOfBoundsException

Reads the specified number of characters from the buffer, converting each two byte unsigned value to a character of the resulting string. Reads values that were written using `TupleOutput.writeChars(java.lang.String)`.

Parameters:
  `length` - is the number of characters to be read.
Returns:
  the value read from the buffer.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readBytes

    public final void readBytes(char[] chars)
                         throws java.lang.IndexOutOfBoundsException

Reads the specified number of bytes from the buffer, converting each unsigned byte value to a character of the resulting array. Reads values that were written using `TupleOutput.writeBytes(java.lang.String)`.

Parameters:
  `chars` - is the array to receive the data and whose length is used to determine the number of bytes to be read.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readChars

    public final void readChars(char[] chars)
                         throws java.lang.IndexOutOfBoundsException

Reads the specified number of characters from the buffer, converting each two byte unsigned value to a character of the resulting array. Reads values that were written using `TupleOutput.writeChars(java.lang.String)`.

Parameters:
  `chars` - is the array to receive the data and whose length is used to determine the number of characters to be read.
Throws:
  `java.lang.IndexOutOfBoundsException` - if not enough bytes are available in the buffer.
See Also:
  Integer Formats

#### readString

    public final java.lang.String readString(int length)
                                      throws java.lang.IndexOutOfBoundsException,
                                             java.lang.IllegalArgumentException

Reads the specified number of UTF characters string from the data buffer and converts the data from UTF to Unicode. Reads values that were written using `TupleOutput.writeString(char[])`.

Parameters:
  `length` - is the number of characters to be read.
Returns:
  the converted string.
Throws:
  `java.lang.IndexOutOfBoundsException` - if no null terminating byte is found in the buffer.
  `java.lang.IllegalArgumentException` - malformed UTF data is encountered.
See Also:
  String Formats

#### readString

    public final void readString(char[] chars)
                          throws java.lang.IndexOutOfBoundsException,
                                 java.lang.IllegalArgumentException

Reads the specified number of UTF characters string from the data buffer and converts the data from UTF to Unicode. Reads values that were written using `TupleOutput.writeString(char[])`.

Parameters:
  `chars` - is the array to receive the data and whose length is used to determine the number of characters to be read.
Throws:
  `java.lang.IndexOutOfBoundsException` - if no null terminating byte is found in the buffer.
  `java.lang.IllegalArgumentException` - malformed UTF data is encountered.
See Also:
  String Formats

#### getStringByteLength

    public final int getStringByteLength()
                                  throws java.lang.IndexOutOfBoundsException,
                                         java.lang.IllegalArgumentException

Returns the byte length of a null-terminated UTF string in the data buffer, including the terminator. Used with string values that were written using `TupleOutput.writeString(String)`.

Returns:
  the byte length.
Throws:
  `java.lang.IndexOutOfBoundsException` - if no null terminating byte is found in the buffer.
  `java.lang.IllegalArgumentException` - malformed UTF data is encountered.
See Also:
  String Formats

#### readPackedInt

    public final int readPackedInt()

Reads an unsorted packed integer.

Returns:
  the int value.
See Also:
  Integer Formats

#### getPackedIntByteLength

    public final int getPackedIntByteLength()

Returns the byte length of a packed integer.

Returns:
  the byte length.
See Also:
  Integer Formats

#### readPackedLong

    public final long readPackedLong()

Reads an unsorted packed long integer.

Returns:
  the long value.
See Also:
  Integer Formats

#### getPackedLongByteLength

    public final int getPackedLongByteLength()

Returns the byte length of a packed long integer.

Returns:
  the byte length.
See Also:
  Integer Formats

#### readSortedPackedInt

    public final int readSortedPackedInt()

Reads a sorted packed integer.

Returns:
  the int value.
See Also:
  Integer Formats

#### getSortedPackedIntByteLength

    public final int getSortedPackedIntByteLength()

Returns the byte length of a sorted packed integer.

Returns:
  the byte length.
See Also:
  Integer Formats

#### readSortedPackedLong

    public final long readSortedPackedLong()

Reads a sorted packed long integer.

Returns:
  the long value.
See Also:
  Integer Formats

#### getSortedPackedLongByteLength

    public final int getSortedPackedLongByteLength()

Returns the byte length of a sorted packed long integer.

Returns:
  the byte length.
See Also:
  Integer Formats

#### readBigInteger

    public final java.math.BigInteger readBigInteger()

Reads a `BigInteger`.

Returns:
  the non-null BigInteger value.
See Also:
  Integer Formats

#### getBigIntegerByteLength

    public final int getBigIntegerByteLength()

Returns the byte length of a `BigInteger`.

Returns:
  the byte length.
See Also:
  Integer Formats

#### readBigDecimal

    public final java.math.BigDecimal readBigDecimal()

Reads an unsorted `BigDecimal`.

Returns:
  the non-null BigDecimal value.
See Also:
  BigDecimal Formats

#### getBigDecimalByteLength

    public final int getBigDecimalByteLength()

Returns the byte length of an unsorted `BigDecimal`.

Returns:
  the byte length.
See Also:
  BigDecimal Formats

#### readSortedBigDecimal

    public final java.math.BigDecimal readSortedBigDecimal()

Reads a sorted `BigDecimal`, with support for correct default sorting.

Returns:
  the non-null BigDecimal value.
See Also:
  BigDecimal Formats

#### getSortedBigDecimalByteLength

    public final int getSortedBigDecimalByteLength()

Returns the byte length of a sorted `BigDecimal`.

Returns:
  the byte length.
See Also:
  BigDecimal Formats