|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
com.sleepycat.util.FastInputStream
com.sleepycat.bind.tuple.TupleInput
public class TupleInput
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.
Signed numbers are stored in the buffer in MSB (most significant byte first) order with their sign bit (high-order bit) inverted to cause negative numbers to be sorted first when comparing values as unsigned byte arrays, as done in a database. Unsigned numbers, including characters, are stored in MSB order with no change to their sign bit.
Strings and character arrays are stored either as a fixed length array of unicode characters, where the length must be known by the application, or as a null-terminated UTF byte array.
Floats and doubles are stored in standard Java integer-bit representation (IEEE 754). Non-negative numbers are correctly ordered by numeric value. However, negative numbers are not correctly ordered; therefore, if you use negative floating point numbers in a key, you'll need to implement and configure a custom comparator to get correct numeric ordering.
Field Summary |
---|
Fields inherited from class com.sleepycat.util.FastInputStream |
---|
buf, len, mark, off |
Constructor Summary | |
---|---|
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 | |
---|---|
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 a signed double (eight byte) value from the buffer. |
float |
readFloat()
Reads a signed 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. |
short |
readShort()
Reads a signed short (two byte) value from the buffer. |
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 |
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 |
---|
public TupleInput(byte[] buffer)
buffer
- is the byte array to be read and should contain data in
tuple format.public TupleInput(byte[] buffer, int offset, int length)
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.public TupleInput(TupleOutput output)
output
- is the tuple output object containing the data to be read.Method Detail |
---|
public final java.lang.String readString() throws java.lang.IndexOutOfBoundsException, java.lang.IllegalArgumentException
TupleOutput.writeString(String)
.
java.lang.IndexOutOfBoundsException
- if no null terminating byte is found
in the buffer.
java.lang.IllegalArgumentException
- malformed UTF data is encountered.public final char readChar() throws java.lang.IndexOutOfBoundsException
TupleOutput.writeChar(int)
.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final boolean readBoolean() throws java.lang.IndexOutOfBoundsException
TupleOutput.writeBoolean(boolean)
.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final byte readByte() throws java.lang.IndexOutOfBoundsException
TupleOutput.writeByte(int)
.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final short readShort() throws java.lang.IndexOutOfBoundsException
TupleOutput.writeShort(int)
.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final int readInt() throws java.lang.IndexOutOfBoundsException
TupleOutput.writeInt(int)
.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final long readLong() throws java.lang.IndexOutOfBoundsException
TupleOutput.writeLong(long)
.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final float readFloat() throws java.lang.IndexOutOfBoundsException
TupleOutput.writeFloat(float)
.
Float.intBitsToFloat
is used to convert the signed int
value.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final double readDouble() throws java.lang.IndexOutOfBoundsException
TupleOutput.writeDouble(double)
.
Double.longBitsToDouble
is used to convert the signed long
value.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final int readUnsignedByte() throws java.lang.IndexOutOfBoundsException
TupleOutput.writeUnsignedByte(int)
.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final int readUnsignedShort() throws java.lang.IndexOutOfBoundsException
TupleOutput.writeUnsignedShort(int)
.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final long readUnsignedInt() throws java.lang.IndexOutOfBoundsException
TupleOutput.writeUnsignedInt(long)
.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final java.lang.String readBytes(int length) throws java.lang.IndexOutOfBoundsException
TupleOutput.writeBytes(java.lang.String)
.
Only characters with values below 0x100 may be read using this method.
length
- is the number of bytes to be read.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final java.lang.String readChars(int length) throws java.lang.IndexOutOfBoundsException
TupleOutput.writeChars(java.lang.String)
.
length
- is the number of characters to be read.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final void readBytes(char[] chars) throws java.lang.IndexOutOfBoundsException
TupleOutput.writeBytes(java.lang.String)
.
Only characters with values below 0x100 may be read using this method.
chars
- is the array to receive the data and whose length is used
to determine the number of bytes to be read.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final void readChars(char[] chars) throws java.lang.IndexOutOfBoundsException
TupleOutput.writeChars(java.lang.String)
.
chars
- is the array to receive the data and whose length is used
to determine the number of characters to be read.
java.lang.IndexOutOfBoundsException
- if not enough bytes are available in
the buffer.public final java.lang.String readString(int length) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalArgumentException
TupleOutput.writeString(char[])
.
length
- is the number of characters to be read.
java.lang.IndexOutOfBoundsException
- if no null terminating byte is found
in the buffer.
java.lang.IllegalArgumentException
- malformed UTF data is encountered.public final void readString(char[] chars) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalArgumentException
TupleOutput.writeString(char[])
.
chars
- is the array to receive the data and whose length is used
to determine the number of characters to be read.
java.lang.IndexOutOfBoundsException
- if no null terminating byte is found
in the buffer.
java.lang.IllegalArgumentException
- malformed UTF data is encountered.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |