|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.sgs.impl.service.data.store.DataEncoding
public final class DataEncoding
Provides methods for encoding and decoding data stored in the database.
| Method Summary | |
|---|---|
static int |
decodeInt(byte[] bytes)
Decodes a four byte array into an int. |
static int |
decodeInt(byte[] bytes,
int offset)
Decodes a four byte subsequence of an array into an int. |
static long |
decodeLong(byte[] bytes)
Decodes an eight byte array into a long. |
static short |
decodeShort(byte[] bytes)
Decodes a two byte array into a short. |
static String |
decodeString(byte[] bytes)
Decodes an array of bytes encoded as modified UTF-8, but with the two-byte size value omitted from the start and with a null termination, into a String. |
static byte[] |
encodeInt(int n)
Encodes an int into a four byte array. |
static void |
encodeInt(int n,
byte[] bytes,
int offset)
Encodes an int into a four byte subsequence of an array. |
static byte[] |
encodeLong(long n)
Encodes a long into an eight byte array. |
static byte[] |
encodeShort(short n)
Encodes a short into a two byte array. |
static byte[] |
encodeString(String string)
Encodes a String into an array of bytes encoded in modified
UTF-8 format, as documented by DataInput, but with the two byte
size value omitted from the start of the encoding, and with a
terminating null byte. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static byte[] encodeShort(short n)
short into a two byte array. The higher order bits of
the value are stored in the first byte. The high order bit of the first
byte is inverted to insure that negative values sort first.
n - the number to encode
public static short decodeShort(byte[] bytes)
short. The higher order bits of
the value are read from the first byte. The high order bit of the first
byte is inverted.
bytes - the byte array to decode
IndexOutOfBoundsException - if bytes is less than two
bytes in length
IllegalArgumentException - if bytes is more than two
bytes in lengthpublic static byte[] encodeInt(int n)
int into a four byte array. The higher order bits of
the value are stored in the lower numbered bytes. The high order bit of
the first byte is inverted to insure that negative values sort first.
n - the number to encode
public static void encodeInt(int n,
byte[] bytes,
int offset)
int into a four byte subsequence of an array. The
higher order bits of the value are stored in the lower numbered bytes.
The high order bit of the first byte is inverted to insure that negative
values sort first.
n - the number to encodebytes - the array in which to store the encoded bytesoffset - the array index at which to store the first byte
IndexOutOfBoundsException - if bytes is not long enough
to contain the encoded bytespublic static int decodeInt(byte[] bytes)
int. The higher order bits of
the value are read from the lower numbered bytes. The high order bit of
the first byte is inverted.
bytes - the byte array to decode
IndexOutOfBoundsException - if bytes is less than four
bytes in length
IllegalArgumentException - if bytes is more than four
bytes in length
public static int decodeInt(byte[] bytes,
int offset)
int. The
higher order bits of the value are read from the lower numbered bytes.
The high order bit of the first byte is inverted.
bytes - the byte array to decodeoffset - the array index of the first byte to decode
IndexOutOfBoundsException - if bytes is not long enough
to contain the encoded bytespublic static byte[] encodeLong(long n)
long into an eight byte array. The higher order bits
of the value are stored in the lower numbered bytes. The high order bit
of the first byte is inverted to insure that negative values sort first.
n - the number to encode
public static long decodeLong(byte[] bytes)
long. The higher order bits
of the value are read from the lower numbered bytes. The high order bit
of the first byte is inverted.
bytes - the byte array to decode
IndexOutOfBoundsException - if bytes is less than eight
bytes in length
IllegalArgumentException - if bytes is more than eight
bytes in lengthpublic static byte[] encodeString(String string)
String into an array of bytes encoded in modified
UTF-8 format, as documented by DataInput, but with the two byte
size value omitted from the start of the encoding, and with a
terminating null byte. Removing the size from the start of the encoding
means that the strings will sort properly when used as keys, and adding
a null termination removes the need to depend on the length of the array
to find the end of the data, which turns out to be useful for Berkeley
DB.
string - the string to encode
IllegalArgumentException - if the UTF-8 encoding of the string
contains more than 65535 characterspublic static String decodeString(byte[] bytes)
String.
bytes - the byte array to decode
IllegalArgumentException - if the format of the bytes is not
valid UTF-8 data, if it is not null terminated, or if it
represents more than 65535 bytes
|
RedDwarf, Version 0.10.1 2010-03-14 10:56:12 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||