Package com.sleepycat.bind.tuple
Class TupleInput
java.lang.Object
java.io.InputStream
com.sleepycat.util.FastInputStream
com.sleepycat.bind.tuple.TupleInput
- All Implemented Interfaces:
Closeable,AutoCloseable
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:
-
Field Summary
Fields inherited from class com.sleepycat.util.FastInputStream
buf, len, mark, off -
Constructor Summary
ConstructorsConstructorDescriptionTupleInput(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
Modifier and TypeMethodDescriptionfinal intReturns the byte length of an unsortedBigDecimal.final intReturns the byte length of aBigInteger.final intReturns the byte length of a packed integer.final intReturns the byte length of a packed long integer.final intReturns the byte length of a sortedBigDecimal.final intReturns the byte length of a sorted packed integer.final intReturns the byte length of a sorted packed long integer.final intReturns the byte length of a null-terminated UTF string in the data buffer, including the terminator.final BigDecimalReads an unsortedBigDecimal.final BigIntegerReads aBigInteger.final booleanReads a boolean (one byte) unsigned value from the buffer and returns true if it is non-zero and false if it is zero.final bytereadByte()Reads a signed byte (one byte) value from the buffer.final voidreadBytes(char[] chars) Reads the specified number of bytes from the buffer, converting each unsigned byte value to a character of the resulting array.final StringreadBytes(int length) Reads the specified number of bytes from the buffer, converting each unsigned byte value to a character of the resulting string.final charreadChar()Reads a char (two byte) unsigned value from the buffer.final voidreadChars(char[] chars) Reads the specified number of characters from the buffer, converting each two byte unsigned value to a character of the resulting array.final StringreadChars(int length) Reads the specified number of characters from the buffer, converting each two byte unsigned value to a character of the resulting string.final doubleReads an unsorted double (eight byte) value from the buffer.final floatReads an unsorted float (four byte) value from the buffer.final intreadInt()Reads a signed int (four byte) value from the buffer.final longreadLong()Reads a signed long (eight byte) value from the buffer.final intReads an unsorted packed integer.final longReads an unsorted packed long integer.final shortReads a signed short (two byte) value from the buffer.final BigDecimalReads a sortedBigDecimal, with support for correct default sorting.final doubleReads a sorted double (eight byte) value from the buffer.final floatReads a sorted float (four byte) value from the buffer.final intReads a sorted packed integer.final longReads a sorted packed long integer.final StringReads a null-terminated UTF string from the data buffer and converts the data from UTF to Unicode.final voidreadString(char[] chars) Reads the specified number of UTF characters string from the data buffer and converts the data from UTF to Unicode.final StringreadString(int length) Reads the specified number of UTF characters string from the data buffer and converts the data from UTF to Unicode.final intReads an unsigned byte (one byte) value from the buffer.final longReads an unsigned int (four byte) value from the buffer.final intReads 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, skipFastMethods inherited from class java.io.InputStream
close, nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
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
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 Details
-
readString
Reads a null-terminated UTF string from the data buffer and converts the data from UTF to Unicode. Reads values that were written usingTupleOutput.writeString(String).- Returns:
- the converted string.
- Throws:
IndexOutOfBoundsException- if no null terminating byte is found in the buffer.IllegalArgumentException- malformed UTF data is encountered.- See Also:
-
readChar
Reads a char (two byte) unsigned value from the buffer. Reads values that were written usingTupleOutput.writeChar(int).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
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. Reads values that were written usingTupleOutput.writeBoolean(boolean).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readByte
Reads a signed byte (one byte) value from the buffer. Reads values that were written usingTupleOutput.writeByte(int).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readShort
Reads a signed short (two byte) value from the buffer. Reads values that were written usingTupleOutput.writeShort(int).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readInt
Reads a signed int (four byte) value from the buffer. Reads values that were written usingTupleOutput.writeInt(int).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readLong
Reads a signed long (eight byte) value from the buffer. Reads values that were written usingTupleOutput.writeLong(long).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readFloat
Reads an unsorted float (four byte) value from the buffer. Reads values that were written usingTupleOutput.writeFloat(float).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readDouble
Reads an unsorted double (eight byte) value from the buffer. Reads values that were written usingTupleOutput.writeDouble(double).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readSortedFloat
Reads a sorted float (four byte) value from the buffer. Reads values that were written usingTupleOutput.writeSortedFloat(float).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readSortedDouble
Reads a sorted double (eight byte) value from the buffer. Reads values that were written usingTupleOutput.writeSortedDouble(double).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readUnsignedByte
Reads an unsigned byte (one byte) value from the buffer. Reads values that were written usingTupleOutput.writeUnsignedByte(int).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readUnsignedShort
Reads an unsigned short (two byte) value from the buffer. Reads values that were written usingTupleOutput.writeUnsignedShort(int).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readUnsignedInt
Reads an unsigned int (four byte) value from the buffer. Reads values that were written usingTupleOutput.writeUnsignedInt(long).- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readBytes
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 usingTupleOutput.writeBytes(java.lang.String).- Parameters:
length- is the number of bytes to be read.- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readChars
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 usingTupleOutput.writeChars(java.lang.String).- Parameters:
length- is the number of characters to be read.- Returns:
- the value read from the buffer.
- Throws:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readBytes
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 usingTupleOutput.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:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readChars
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 usingTupleOutput.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:
IndexOutOfBoundsException- if not enough bytes are available in the buffer.- See Also:
-
readString
public final String readString(int length) throws IndexOutOfBoundsException, 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 usingTupleOutput.writeString(char[]).- Parameters:
length- is the number of characters to be read.- Returns:
- the converted string.
- Throws:
IndexOutOfBoundsException- if no null terminating byte is found in the buffer.IllegalArgumentException- malformed UTF data is encountered.- See Also:
-
readString
public final void readString(char[] chars) throws IndexOutOfBoundsException, 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 usingTupleOutput.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:
IndexOutOfBoundsException- if no null terminating byte is found in the buffer.IllegalArgumentException- malformed UTF data is encountered.- See Also:
-
getStringByteLength
Returns the byte length of a null-terminated UTF string in the data buffer, including the terminator. Used with string values that were written usingTupleOutput.writeString(String).- Throws:
IndexOutOfBoundsException- if no null terminating byte is found in the buffer.IllegalArgumentException- malformed UTF data is encountered.- See Also:
-
readPackedInt
public final int readPackedInt()Reads an unsorted packed integer.- See Also:
-
getPackedIntByteLength
public final int getPackedIntByteLength()Returns the byte length of a packed integer.- See Also:
-
readPackedLong
public final long readPackedLong()Reads an unsorted packed long integer.- See Also:
-
getPackedLongByteLength
public final int getPackedLongByteLength()Returns the byte length of a packed long integer.- See Also:
-
readSortedPackedInt
public final int readSortedPackedInt()Reads a sorted packed integer.- See Also:
-
getSortedPackedIntByteLength
public final int getSortedPackedIntByteLength()Returns the byte length of a sorted packed integer.- See Also:
-
readSortedPackedLong
public final long readSortedPackedLong()Reads a sorted packed long integer.- See Also:
-
getSortedPackedLongByteLength
public final int getSortedPackedLongByteLength()Returns the byte length of a sorted packed long integer.- See Also:
-
readBigInteger
Reads aBigInteger.- See Also:
-
getBigIntegerByteLength
public final int getBigIntegerByteLength()Returns the byte length of aBigInteger.- See Also:
-
readBigDecimal
Reads an unsortedBigDecimal.- See Also:
-
getBigDecimalByteLength
public final int getBigDecimalByteLength()Returns the byte length of an unsortedBigDecimal.- See Also:
-
readSortedBigDecimal
Reads a sortedBigDecimal, with support for correct default sorting.- See Also:
-
getSortedBigDecimalByteLength
public final int getSortedBigDecimalByteLength()Returns the byte length of a sortedBigDecimal.- See Also:
-