Berkeley DB
version 4.2.52

com.sleepycat.bdb.bind.tuple
Class TupleInput

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

public class TupleInput
extends FastInputStream

Used by tuple bindings to read tuple data.

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 integer-bit representation and are therefore not ordered by numeric value.


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.
 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.
 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.
 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.
 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.bdb.util.FastInputStream
available, getBufferBytes, getBufferLength, getBufferOffset, mark, markSupported, read, read, read, reset, skip
 
Methods inherited from class java.io.InputStream
close
 
Methods inherited from class java.lang.Object
equals, 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 String readString()
                        throws IOException
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:
IOException - if no null terminating byte is found in the buffer or malformed UTF data is encountered.

readChar

public final char readChar()
                    throws IOException
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:
IOException - if not enough bytes are available in the buffer.

readBoolean

public final boolean readBoolean()
                          throws IOException
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:
IOException - if not enough bytes are available in the buffer.

readByte

public final byte readByte()
                    throws IOException
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:
IOException - if not enough bytes are available in the buffer.

readShort

public final short readShort()
                      throws IOException
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:
IOException - if not enough bytes are available in the buffer.

readInt

public final int readInt()
                  throws IOException
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:
IOException - if not enough bytes are available in the buffer.

readLong

public final long readLong()
                    throws IOException
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:
IOException - if not enough bytes are available in the buffer.

readFloat

public final float readFloat()
                      throws IOException
Reads a signed float (four byte) value from the buffer. Reads values that were written using TupleOutput.writeFloat(float). Float.intBitsToFloat is used to convert the signed int value.

Returns:
the value read from the buffer.
Throws:
IOException - if not enough bytes are available in the buffer.

readDouble

public final double readDouble()
                        throws IOException
Reads a signed double (eight byte) value from the buffer. Reads values that were written using TupleOutput.writeDouble(double). Double.longBitsToDouble is used to convert the signed long value.

Returns:
the value read from the buffer.
Throws:
IOException - if not enough bytes are available in the buffer.

readUnsignedByte

public final int readUnsignedByte()
                           throws IOException
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:
IOException - if not enough bytes are available in the buffer.

readUnsignedShort

public final int readUnsignedShort()
                            throws IOException
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:
IOException - if not enough bytes are available in the buffer.

readUnsignedInt

public final long readUnsignedInt()
                           throws IOException
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:
IOException - if not enough bytes are available in the buffer.

readBytes

public final String readBytes(int length)
                       throws IOException
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). Only characters with values below 0x100 may be read using this method.

Parameters:
length - is the number of bytes to be read.
Returns:
the value read from the buffer.
Throws:
IOException - if not enough bytes are available in the buffer.

readChars

public final String readChars(int length)
                       throws IOException
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:
IOException - if not enough bytes are available in the buffer.

readBytes

public final void readBytes(char[] chars)
                     throws IOException
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). Only characters with values below 0x100 may be read using this method.

Parameters:
chars - is the array to receive the data and whose length is used to determine the number of bytes to be read.
Returns:
the value read from the buffer.
Throws:
IOException - if not enough bytes are available in the buffer.

readChars

public final void readChars(char[] chars)
                     throws IOException
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.
Returns:
the value read from the buffer.
Throws:
IOException - if not enough bytes are available in the buffer.

readString

public final String readString(int length)
                        throws IOException
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:
IOException - if not enough bytes are available in the buffer or malformed UTF data is encountered.

readString

public final void readString(char[] chars)
                      throws IOException
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.
Returns:
the converted string.
Throws:
IOException - if not enough bytes are available in the buffer or malformed UTF data is encountered.

Berkeley DB
version 4.2.52

Copyright (c) 1996-2003 Sleepycat Software, Inc. - All rights reserved.