Servertec
Persistent Object Store
1.4.1 09/04/2005

stec.pos
Class ByteArray

java.lang.Object
  extended by stec.pos.ByteArray

public final class ByteArray
extends java.lang.Object

Static methods for manipulating byte arrays used by when storing and retrieving key, value pairs from peristent object stores and indexes.

Since:
1.0.0 08/12/2001

Field Summary
static byte BIGDECIMAL
          Specifies a BigDecimal.
static byte BIGINTEGER
          Specifies a BigInteger.
static byte BLOB
          Specifies a Blob.
static byte BOOLEAN
          Specifies a boolean.
static byte BYTE
          Specifies a byte.
static byte BYTE_ARRAY
          Specifies an array of bytes.
static byte CHAR
          Specifies a char.
static byte DATE
          Specifies a Date.
static byte DOUBLE
          Specifies a double.
static byte DUPLICATES
          Specifies duplicates.
static byte FLOAT
          Specifies a float.
static byte INT
          Specifies an int.
static byte LONG
          Specifies a long.
static byte NULL
          Specifies a null.
static byte OBJECT
          Specifies an Object.
static byte SHORT
          Specifies a short.
static byte STRING
          Specifies a String.
 
Constructor Summary
ByteArray()
           
 
Method Summary
static java.lang.Object decodeObject(byte[] bytes, int offset)
          Returns the Object encoded at the specified offset in the given byte array.
static void encodeObject(byte[] bytes, int offset, java.lang.Object object)
          Encodes the given Object at the specified offset in the given byte array.
static java.math.BigDecimal getBigDecimal(byte[] bytes, int offset)
          Returns the java.math.BigDecimal at the specified offset in the given byte array.
static java.math.BigInteger getBigInteger(byte[] bytes, int offset)
          Returns the java.math.BigInteger at the specified offset in the given byte array.
static Blob getBlob(byte[] bytes, int offset)
          Returns the Blob at the specified offset in the given byte array.
static boolean getBoolean(byte[] bytes, int offset)
          Returns the boolean at the specified offset in the given byte array.
static byte getByte(byte[] bytes, int offset)
          Returns the byte at the specified offset in the given byte array.
static byte[] getByteArray(byte[] bytes, int offset)
          Returns the byte array at the specified offset in the given byte array.
static char getChar(byte[] bytes, int offset)
          Returns the char at the specified offset in the given byte array.
static java.util.Date getDate(byte[] bytes, int offset)
          Returns the Date at the specified offset in the given byte array.
static double getDouble(byte[] bytes, int offset)
          Returns the double at the specified offset in the given byte array.
static int getEncodedObjectLength(java.lang.Object object)
          Returns the number of bytes needed by the specifed Object when converted into an encoded byte array.
static int getEncodedType(java.lang.Object object)
          Returns the encoded type.
static float getFloat(byte[] bytes, int offset)
          Returns the float at the specified offset in the given byte array.
static int getInt(byte[] bytes, int offset)
          Returns the int at the specified offset in the given byte array.
static long getLong(byte[] bytes, int offset)
          Returns the long at the specified offset in the given byte array.
static java.lang.Object getObject(byte[] bytes, int offset)
          Returns the Object at the specified offset in the given byte array.
static int getObjectLength(java.lang.Object object)
          Returns the number of bytes needed by the specifed Object when converted into a byte array.
static short getShort(byte[] bytes, int offset)
          Returns the short at the specified offset in the given byte array.
static java.lang.String getString(byte[] bytes, int offset)
          Returns the String at the specified offset in the given byte array.
static int getStringLength(java.lang.String string)
          Returns the number of bytes needed by the specifed String when converted into an encoded byte array.
static java.lang.String getUtf8String(byte[] bytes, int offset)
          Returns the UTF-8 encoded String at the specified offset in the given byte array.
static int getUtf8StringLength(java.lang.String string)
          Returns the number of bytes needed by the specifed String when converted into a UTF-8 encoded byte array.
static void setBigDecimal(byte[] bytes, int offset, java.math.BigDecimal decimal)
          Sets the java.math.BigDecimal at the specified offset in the given byte array to the specified decimal.
static void setBigInteger(byte[] bytes, int offset, java.math.BigInteger integer)
          Sets the java.math.BigInteger at the specified offset in the given byte array to the specified integer.
static void setBlob(byte[] bytes, int offset, Blob blob)
          Sets the Blob at the specified offset in the given byte array to the specified Blob.
static void setBoolean(byte[] bytes, int offset, boolean b)
          Sets the boolean at the specified offset in the given byte array to the specified boolean.
static void setByte(byte[] bytes, int offset, int b)
          Sets the byte at the specified offset in the given byte array to the specified byte.
static void setByteArray(byte[] bytes, int offset, byte[] byte_array)
          Sets the byte array at the specified offset in the given byte array to the specified byte array.
static void setChar(byte[] bytes, int offset, int c)
          Sets the char at the specified offset in the given byte array to the specified char.
static void setDate(byte[] bytes, int offset, java.util.Date date)
          Sets the Date at the specified offset in the given byte array to the specified Date.
static void setDouble(byte[] bytes, int offset, double d)
          Sets the double at the specified offset in the given byte array to the specified double.
static void setFloat(byte[] bytes, int offset, float f)
          Sets the float at the specified offset in the given byte array to the specified float.
static void setInt(byte[] bytes, int offset, int i)
          Sets the int at the specified offset in the given byte array to the specified int.
static void setLong(byte[] bytes, int offset, long l)
          Sets the long at the specified offset in the given byte array to the specified long.
static void setObject(byte[] bytes, int offset, java.lang.Object object)
          Sets the Object at the specified offset in the given byte array to the specified Object.
static void setShort(byte[] bytes, int offset, int s)
          Sets the short at the specified offset in the given byte array to the specified short.
static void setString(byte[] bytes, int offset, java.lang.String string)
          Sets the String at the specified offset in the given byte array to the specified String.
static void setUtf8String(byte[] bytes, int offset, java.lang.String string)
          Sets the UTF-8 encoded String at the specified offset in the given byte array to the specified String.
static byte[] toByteArray(java.lang.Object object)
          Returns a byte array containing the specified Object.
static byte[] toEncodedByteArray(java.lang.Object object)
          Returns a byte array containing the specified Object encoded.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL

public static final byte NULL
Specifies a null.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

BYTE

public static final byte BYTE
Specifies a byte.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

CHAR

public static final byte CHAR
Specifies a char.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

SHORT

public static final byte SHORT
Specifies a short.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

INT

public static final byte INT
Specifies an int.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

LONG

public static final byte LONG
Specifies a long.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

FLOAT

public static final byte FLOAT
Specifies a float.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

DOUBLE

public static final byte DOUBLE
Specifies a double.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

STRING

public static final byte STRING
Specifies a String.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

OBJECT

public static final byte OBJECT
Specifies an Object.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

BOOLEAN

public static final byte BOOLEAN
Specifies a boolean.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

BLOB

public static final byte BLOB
Specifies a Blob.

Used when encoding Objects and decoding Objects.

See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

DATE

public static final byte DATE
Specifies a Date.

Used when encoding Objects and decoding Objects.

Since:
1.1.0 09/01/2002
See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

BIGINTEGER

public static final byte BIGINTEGER
Specifies a BigInteger.

Used when encoding Objects and decoding Objects.

Since:
1.1.0 09/01/2002
See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

BIGDECIMAL

public static final byte BIGDECIMAL
Specifies a BigDecimal.

Used when encoding Objects and decoding Objects.

Since:
1.1.0 09/01/2002
See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

BYTE_ARRAY

public static final byte BYTE_ARRAY
Specifies an array of bytes.

Used when encoding Objects and decoding Objects.

Since:
1.3.0 10/19/2003
See Also:
encodeObject, decodeObject, toByteArray, Constant Field Values

DUPLICATES

public static final byte DUPLICATES
Specifies duplicates.

Used to specify the data type for values when the index being used supports duplicates. Used by indexes when support for duplicates is specified.

Since:
1.1.0 09/01/2002
See Also:
Constant Field Values
Constructor Detail

ByteArray

public ByteArray()
Method Detail

getByte

public static final byte getByte(byte[] bytes,
                                 int offset)
Returns the byte at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the byte at the specified offset in the given byte array.

setByte

public static final void setByte(byte[] bytes,
                                 int offset,
                                 int b)
Sets the byte at the specified offset in the given byte array to the specified byte.

Parameters:
bytes - the byte array.
offset - the offset.
b - the byte to use.

getChar

public static final char getChar(byte[] bytes,
                                 int offset)
Returns the char at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the char at the specified offset in the given byte array.

setChar

public static final void setChar(byte[] bytes,
                                 int offset,
                                 int c)
Sets the char at the specified offset in the given byte array to the specified char.

Parameters:
bytes - the byte array.
offset - the offset.
c - the character to use.

getShort

public static final short getShort(byte[] bytes,
                                   int offset)
Returns the short at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the short at the specified offset in the given byte array.

setShort

public static final void setShort(byte[] bytes,
                                  int offset,
                                  int s)
Sets the short at the specified offset in the given byte array to the specified short.

Parameters:
bytes - the byte array.
offset - the offset.
s - the short to use.

getInt

public static final int getInt(byte[] bytes,
                               int offset)
Returns the int at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the int at the specified offset in the given byte array.

setInt

public static final void setInt(byte[] bytes,
                                int offset,
                                int i)
Sets the int at the specified offset in the given byte array to the specified int.

Parameters:
bytes - the byte array.
offset - the offset.
i - the integer to use.

getLong

public static final long getLong(byte[] bytes,
                                 int offset)
Returns the long at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the long at the specified offset in the given byte array.

setLong

public static final void setLong(byte[] bytes,
                                 int offset,
                                 long l)
Sets the long at the specified offset in the given byte array to the specified long.

Parameters:
bytes - the byte array.
offset - the offset.
l - the long to use.

getFloat

public static final float getFloat(byte[] bytes,
                                   int offset)
Returns the float at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the float at the specified offset in the given byte array.

setFloat

public static final void setFloat(byte[] bytes,
                                  int offset,
                                  float f)
Sets the float at the specified offset in the given byte array to the specified float.

Parameters:
bytes - the byte array.
offset - the offset.
f - the float to use.

getDouble

public static final double getDouble(byte[] bytes,
                                     int offset)
Returns the double at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the double at the specified offset in the given byte array.

setDouble

public static final void setDouble(byte[] bytes,
                                   int offset,
                                   double d)
Sets the double at the specified offset in the given byte array to the specified double.

Parameters:
bytes - the byte array.
offset - the offset.
d - the double to use.

getBoolean

public static final boolean getBoolean(byte[] bytes,
                                       int offset)
Returns the boolean at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the boolean at the specified offset in the given byte array.

setBoolean

public static final void setBoolean(byte[] bytes,
                                    int offset,
                                    boolean b)
Sets the boolean at the specified offset in the given byte array to the specified boolean.

Parameters:
bytes - the byte array.
offset - the offset.
b - the boolean to use.

getString

public static final java.lang.String getString(byte[] bytes,
                                               int offset)
                                        throws java.io.UTFDataFormatException
Returns the String at the specified offset in the given byte array.

Encoding: utf_8_string_value

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the String.
Throws:
java.io.UTFDataFormatException - if the String is not UTF-8 encoded.

setString

public static final void setString(byte[] bytes,
                                   int offset,
                                   java.lang.String string)
Sets the String at the specified offset in the given byte array to the specified String.

Encoding: utf_8_string_value

Parameters:
bytes - the byte array.
offset - the offset.
string - the String to use.

getUtf8String

public static final java.lang.String getUtf8String(byte[] bytes,
                                                   int offset)
                                            throws java.io.UTFDataFormatException
Returns the UTF-8 encoded String at the specified offset in the given byte array.

Encoding: 4_byte_utf_8_string_length utf_8_string_value

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the UTF-8 encoded String.
Throws:
java.io.UTFDataFormatException - if the String is not UTF-8 encoded.

setUtf8String

public static final void setUtf8String(byte[] bytes,
                                       int offset,
                                       java.lang.String string)
Sets the UTF-8 encoded String at the specified offset in the given byte array to the specified String.

Encoding: 4_byte_utf_8_string_length utf_8_string_value

Parameters:
bytes - the byte array.
offset - the offset.
string - the String to use.

getObject

public static final java.lang.Object getObject(byte[] bytes,
                                               int offset)
                                        throws java.lang.ClassNotFoundException,
                                               java.io.OptionalDataException,
                                               java.io.IOException
Returns the Object at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the Object at the specified offset in the given byte array.
Throws:
java.lang.ClasSNotFoundException - if the named class is not defined.
java.io.OptionalDataException - if the class encoding is invalid.
java.io.IOException - if an I/O exception occurred.
java.lang.ClassNotFoundException

setObject

public static final void setObject(byte[] bytes,
                                   int offset,
                                   java.lang.Object object)
                            throws java.io.IOException
Sets the Object at the specified offset in the given byte array to the specified Object.

Parameters:
bytes - the byte array.
offset - the offset.
object - the Object to use.
Throws:
java.io.IOException - if an I/O exception occurred.

getBlob

public static final Blob getBlob(byte[] bytes,
                                 int offset)
Returns the Blob at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the Blob at the specified offset in the given byte array.

setBlob

public static final void setBlob(byte[] bytes,
                                 int offset,
                                 Blob blob)
Sets the Blob at the specified offset in the given byte array to the specified Blob.

Parameters:
bytes - the byte array.
offset - the offset.
blob - the Blob to use.

getDate

public static final java.util.Date getDate(byte[] bytes,
                                           int offset)
Returns the Date at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the Date at the specified offset in the given byte array.
Since:
1.1.0 09/01/2002

setDate

public static final void setDate(byte[] bytes,
                                 int offset,
                                 java.util.Date date)
Sets the Date at the specified offset in the given byte array to the specified Date.

Parameters:
bytes - the byte array.
offset - the offset.
date - the Date to use.
Since:
1.1.0 09/01/2002

getBigInteger

public static final java.math.BigInteger getBigInteger(byte[] bytes,
                                                       int offset)
Returns the java.math.BigInteger at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the BigInteger at the specified offset in the given byte array.
Since:
1.1.0 09/01/2002

setBigInteger

public static final void setBigInteger(byte[] bytes,
                                       int offset,
                                       java.math.BigInteger integer)
Sets the java.math.BigInteger at the specified offset in the given byte array to the specified integer.

Parameters:
bytes - the byte array.
offset - the offset.
integer - the BigInteger to use.
Since:
1.1.0 09/01/2002

getBigDecimal

public static final java.math.BigDecimal getBigDecimal(byte[] bytes,
                                                       int offset)
Returns the java.math.BigDecimal at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the BigDecimal at the specified offset in the given byte array.
Since:
1.1.0 09/01/2002

setBigDecimal

public static final void setBigDecimal(byte[] bytes,
                                       int offset,
                                       java.math.BigDecimal decimal)
Sets the java.math.BigDecimal at the specified offset in the given byte array to the specified decimal.

Parameters:
bytes - the byte array.
offset - the offset.
decimal - the BigDecimal to use.
Since:
1.1.0 09/01/2002

getByteArray

public static final byte[] getByteArray(byte[] bytes,
                                        int offset)
Returns the byte array at the specified offset in the given byte array.

Parameters:
bytes - the byte array.
offset - the offset.
Returns:
the byte array at the specified offset in the given byte array.
Since:
1.3.0 10/19/2003

setByteArray

public static final void setByteArray(byte[] bytes,
                                      int offset,
                                      byte[] byte_array)
Sets the byte array at the specified offset in the given byte array to the specified byte array.

Parameters:
bytes - the byte array.
offset - the offset.
byte_array - the array of bytes to use.
Since:
1.3.0 10/19/2003

decodeObject

public static final java.lang.Object decodeObject(byte[] bytes,
                                                  int offset)
                                           throws java.lang.ClassNotFoundException,
                                                  java.io.OptionalDataException,
                                                  java.io.UTFDataFormatException,
                                                  java.io.IOException
Returns the Object encoded at the specified offset in the given byte array.

Encoding: 1_byte_type encoded_object

Parameters:
bytes - the byte array.
offset - the byte array.
Returns:
the Object in the specified byte array.
Throws:
java.lang.ClasSNotFoundException - if the named class is not defined.
java.io.OptionalDataException - if the class encoding is invalid.
java.io.UTFDataFormatException - if the String is not UTF-8 encoded.
java.io.IOException - if an I/O exception occurred.
java.lang.ClassNotFoundException

encodeObject

public static final void encodeObject(byte[] bytes,
                                      int offset,
                                      java.lang.Object object)
                               throws java.io.IOException
Encodes the given Object at the specified offset in the given byte array.

Encoding: 1_byte_type encoded_object

Parameters:
bytes - the byte array.
offset - the offset.
object - the Object to use.
Throws:
java.io.IOException - if an I/O exception occurred.

toByteArray

public static final byte[] toByteArray(java.lang.Object object)
                                throws java.io.IOException
Returns a byte array containing the specified Object.

Parameters:
object - the Object to use.
Returns:
byte array containing the specified Object.
Throws:
java.io.IOException - if an I/O exception occurred.

toEncodedByteArray

public static final byte[] toEncodedByteArray(java.lang.Object object)
                                       throws java.io.IOException
Returns a byte array containing the specified Object encoded.

Encoding: 1_byte_type encoded_object

Parameters:
object - the Object to use.
Returns:
byte array containing the specified Object.
Throws:
java.io.IOException - if an I/O exception occurred.

getEncodedType

public static final int getEncodedType(java.lang.Object object)
Returns the encoded type.

Parameters:
object - the Object to use.
Returns:
the encoded type.
Since:
1.3.0 10/19/2003

getStringLength

public static final int getStringLength(java.lang.String string)
Returns the number of bytes needed by the specifed String when converted into an encoded byte array.

Parameters:
string - the specified String.
Returns:
the encoded length of the specified String.

getUtf8StringLength

public static final int getUtf8StringLength(java.lang.String string)
Returns the number of bytes needed by the specifed String when converted into a UTF-8 encoded byte array.

same as getStringLength() + 4

Encoding: 4_byte_utf_8_string_length utf_8_string_value

Parameters:
string - the specified String.
Returns:
the UTF-8 length of the specified String.

getObjectLength

public static final int getObjectLength(java.lang.Object object)
                                 throws java.io.IOException
Returns the number of bytes needed by the specifed Object when converted into a byte array.

Parameters:
object - the specified Object.
Returns:
the number of bytes of the specified Object.
Throws:
java.io.IOException - if an I/O exception occurred.

getEncodedObjectLength

public static final int getEncodedObjectLength(java.lang.Object object)
                                        throws java.io.IOException
Returns the number of bytes needed by the specifed Object when converted into an encoded byte array.

same as getObjectLength() + 1

Encoding: 1_byte_type encoded_object

Parameters:
object - the specified Object.
Returns:
the number of bytes of the specified Object.
Throws:
java.io.IOException - if an I/O exception occurred.

Servertec
Persistent Object Store
1.4.1 09/04/2005

Copyright © 2001-2005 Servertec. All rights reserved.