| 
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--ostore.util.ByteUtils
ByteUtils is a class with commonly needed operations for converting various built-in types to bytes and back.
| Field Summary | |
|---|---|
static char[] | 
digits
A nibble->char mapping for printing out bytes.  | 
static int | 
SIZE_BOOL
 | 
static int | 
SIZE_DOUBLE
 | 
static int | 
SIZE_INT
 | 
static int | 
SIZE_LONG
 | 
static int | 
SIZE_SHORT
 | 
| Constructor Summary | |
|---|---|
ByteUtils()
 | 
|
| Method Summary | |
|---|---|
static void | 
bigIntegerToBytes(BigInteger n,
                  byte[] data,
                  int[] offset)
Write the bytes representing n into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise. | 
static void | 
boolToBytes(boolean b,
            byte[] data,
            int[] offset)
Write the bytes representing b into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise. | 
static BigInteger | 
bytesToBigInteger(byte[] data,
                  int[] offset)
Return the BigInteger represented by the bytes in
 data staring at offset offset[0]. | 
static boolean | 
bytesToBool(byte[] data,
            int[] offset)
Return the boolean represented by the bytes in
 data staring at offset offset[0]. | 
static double | 
bytesToDouble(byte[] data,
              int[] offset)
Return the double represented by the bytes in
 data staring at offset offset[0]. | 
static int | 
bytesToInt(byte[] data,
           int[] offset)
Return the int represented by the bytes in
 data staring at offset offset[0]. | 
static void | 
bytesToInts(int[] dst,
            int dst_offset,
            byte[] src,
            int src_offset,
            int length)
Convert an array of bytess into an array of
 ints. | 
static long | 
bytesToLong(byte[] data,
            int[] offset)
Return the long represented by the bytes in
 data staring at offset offset[0]. | 
static short | 
bytesToShort(byte[] data,
             int[] offset)
Return the short represented by the bytes in
 data staring at offset offset[0]. | 
static String | 
bytesToString(byte[] data,
              int[] offset)
Return the String represented by the bytes in
 data staring at offset offset[0].
  | 
static int | 
byteToUnsignedInt(byte b)
Convert a byte into an unsigned integer. | 
static void | 
doubleToBytes(double d,
              byte[] data,
              int[] offset)
Write the bytes representing d into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise. | 
static boolean | 
equals(byte[] b1,
       byte[] b2)
Determines whether two arrays of bytes contain the same
 contents. | 
static void | 
intsToBytes(byte[] dst,
            int dst_offset,
            int[] src,
            int src_offset,
            int length)
Convert an array of ints into an array of
 bytes. | 
static void | 
intToBytes(int i,
           byte[] data,
           int[] offset)
Write the bytes representing i into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise. | 
static void | 
longToBytes(long l,
            byte[] data,
            int[] offset)
Write the bytes representing l into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise. | 
static void | 
memclr(byte[] array,
       int offset,
       int length)
Fill the given array with zeros.  | 
static boolean | 
memcmp(byte[] a,
       int a_offset,
       byte[] b,
       int b_offset,
       int length)
Compare the contents of one array of bytes to another. | 
static int | 
memcpy(byte[] dst,
       int dst_offset,
       byte[] src,
       int src_offset,
       int length)
Copy contents of one array of bytes into another.
  | 
static String | 
print_bytes_exact(byte[] data,
                  int offset,
                  int length)
 | 
static String | 
print_bytes(byte[] data)
 | 
static String | 
print_bytes(byte[] data,
            int offset,
            int length)
Produce a String representation for the specified array of
 bytes.   | 
static QuickSerializable | 
qs_clone(QuickSerializable qs)
Clone a QuickSerializable object.  | 
static int | 
qs_length(QuickSerializable qs)
Returns the length of the byte array required to store a QuickSerializable object.   | 
static byte[] | 
qs_to_bytes(QuickSerializable qs)
Returns a byte array containing the serialized version of an object.  | 
static int | 
round_up(int value,
         int multiple)
Round a number up to a given multiple.  | 
static void | 
shortToBytes(short s,
             byte[] data,
             int[] offset)
Write the bytes representing s into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise. | 
static void | 
stringToBytes(String s,
              byte[] data,
              int[] offset)
Write the bytes representing s into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise. | 
static byte[] | 
zero_pad(byte[] original,
         int block_size)
Return a new array equal to original except zero-padded to an integral mulitple of blocks.  | 
| Methods inherited from class java.lang.Object | 
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
public static final int SIZE_BOOL
public static final int SIZE_SHORT
public static final int SIZE_INT
public static final int SIZE_LONG
public static final int SIZE_DOUBLE
public static final char[] digits
| Constructor Detail | 
public ByteUtils()
| Method Detail | 
public static final int qs_length(QuickSerializable qs)
QuickSerializable object.  This method calls
 qs.to_bytes, and therefore might be expensive.
qs - The QuickSerializable object to measure.
qs.public static final byte[] qs_to_bytes(QuickSerializable qs)
qs - The object to serialize
bytes, filled in by
 			qs.to_bytes.public static QuickSerializable qs_clone(QuickSerializable qs)
public static final int bytesToInt(byte[] data,
                                   int[] offset)
int represented by the bytes in
 data staring at offset offset[0].
data - the array from which to readoffset - A single element array whose first element is the
 			index in data from which to begin reading on 
                  function entry, and which on function exit has been
                  incremented by the number of bytes read.
int decoded
public static final void intToBytes(int i,
                                    byte[] data,
                                    int[] offset)
i into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise.
i - the int to encodedata - The byte array to store into, or null.offset - A single element array whose first
                  element is the index in data to begin writing at on
                  function entry, and which on function exit has been
                  incremented by the number of bytes written.
public static final short bytesToShort(byte[] data,
                                       int[] offset)
short represented by the bytes in
 data staring at offset offset[0].
data - the array from which to readoffset - A single element array whose first element is the
 			index in data from which to begin reading on 
                  function entry, and which on function exit has been
                  incremented by the number of bytes read.
short decoded
public static final void shortToBytes(short s,
                                      byte[] data,
                                      int[] offset)
s into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise.
s - the short to encodedata - The byte array to store into, or null.offset - A single element array whose first
                  element is the index in data to begin writing at on
                  function entry, and which on function exit has been
                  incremented by the number of bytes written.
public static final long bytesToLong(byte[] data,
                                     int[] offset)
long represented by the bytes in
 data staring at offset offset[0].
data - the array from which to readoffset - A single element array whose first element is the
 			index in data from which to begin reading on 
                  function entry, and which on function exit has been
                  incremented by the number of bytes read.
long decoded
public static final void longToBytes(long l,
                                     byte[] data,
                                     int[] offset)
l into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise.
l - the long to encodedata - The byte array to store into, or null.offset - A single element array whose first
                  element is the index in data to begin writing at on
                  function entry, and which on function exit has been
                  incremented by the number of bytes written.
public static final double bytesToDouble(byte[] data,
                                         int[] offset)
double represented by the bytes in
 data staring at offset offset[0].
data - the array from which to readoffset - A single element array whose first element is the
 			index in data from which to begin reading on 
                  function entry, and which on function exit has been
                  incremented by the number of bytes read.
double decoded
public static final void doubleToBytes(double d,
                                       byte[] data,
                                       int[] offset)
d into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise.
d - the double to encodedata - The byte array to store into, or null.offset - A single element array whose first
                  element is the index in data to begin writing at on
                  function entry, and which on function exit has been
                  incremented by the number of bytes written.
public static final String bytesToString(byte[] data,
                                         int[] offset)
String represented by the bytes in
 data staring at offset offset[0].
 This method relies on the user using the corresponding
 stringToBytes  method to encode the String,
 so that it may properly retrieve the String length.
data - the array from which to readoffset - A single element array whose first element is the
 			index in data from which to begin reading on 
                  function entry, and which on function exit has been
                  incremented by the number of bytes read.
String decoded
public static final void stringToBytes(String s,
                                       byte[] data,
                                       int[] offset)
s into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise.
s - the String to encodedata - The byte array to store into, or null.offset - A single element array whose first
                  element is the index in data to begin writing at on
                  function entry, and which on function exit has been
                  incremented by the number of bytes written.
public static final boolean bytesToBool(byte[] data,
                                        int[] offset)
boolean represented by the bytes in
 data staring at offset offset[0].
data - the array from which to readoffset - A single element array whose first element is the
 			index in data from which to begin reading on 
                  function entry, and which on function exit has been
                  incremented by the number of bytes read.
boolean decoded
public static final void boolToBytes(boolean b,
                                     byte[] data,
                                     int[] offset)
b into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise.
b - the boolean to encodedata - The byte array to store into, or null.offset - A single element array whose first
                  element is the index in data to begin writing at on
                  function entry, and which on function exit has been
                  incremented by the number of bytes written.
public static final BigInteger bytesToBigInteger(byte[] data,
                                                 int[] offset)
BigInteger represented by the bytes in
 data staring at offset offset[0].
data - the array from which to readoffset - A single element array whose first element is the
 			index in data from which to begin reading on 
                  function entry, and which on function exit has been
                  incremented by the number of bytes read.
BigInteger decoded
public static final void bigIntegerToBytes(BigInteger n,
                                           byte[] data,
                                           int[] offset)
n into the byte array
 data, starting at index offset [0], and
 increment offset [0] by the number of bytes written;
 if data == null, increment offset [0] by
 the number of bytes that would have been written otherwise.
n - the BigInteger to encodedata - The byte array to store into, or null.offset - A single element array whose first
                  element is the index in data to begin writing at on
                  function entry, and which on function exit has been
                  incremented by the number of bytes written.
public static final void bytesToInts(int[] dst,
                                     int dst_offset,
                                     byte[] src,
                                     int src_offset,
                                     int length)
bytess into an array of
 ints.
dst - the array to writedst_offset - the start offset in dst, times 4.
		This measures the offset as if dst were an
		array of bytes (rather than ints).src - the array to readsrc_offset - the start offset in srclength - the number of bytes to copy.
public static final void intsToBytes(byte[] dst,
                                     int dst_offset,
                                     int[] src,
                                     int src_offset,
                                     int length)
ints into an array of
 bytes.
dst - the array to writedst_offset - the start offset in dstsrc - the array to readsrc_offset - the start offset in src, times 4.
		This measures the offset as if src were an
		array of bytes (rather than ints).length - the number of bytes to copy.public static final int byteToUnsignedInt(byte b)
byte into an unsigned integer.
b - the byte to cast
int whose lowest byte contains the
 bits of b.
public static int memcpy(byte[] dst,
                         int dst_offset,
                         byte[] src,
                         int src_offset,
                         int length)
bytes into another.
 If either array is null, simply return the
 length parameter directly.
dst - the array to write, or nulldst_offset - the start offset in dstsrc - the array to read, or nullsrc_offset - the start offset in srclength - the number of bytes to copy.
public static boolean memcmp(byte[] a,
                             int a_offset,
                             byte[] b,
                             int b_offset,
                             int length)
bytes to another.
a - the first arraya_offset - the start offset in ab - the second arrayb_offset - the start offset in blength - the number of bytes to compare.
public static void memclr(byte[] array,
                          int offset,
                          int length)
array - the array to clearoffset - the start offsetlength - the number of bytes to clear.
public static int round_up(int value,
                           int multiple)
value - the number to be roundedmultiple - the number to which to be rounded
int greater than or equal to
 value which divides multiple exactly.
public static byte[] zero_pad(byte[] original,
                              int block_size)
original - the array of bytes to be paddedblock_size - the size of the blocks
block_size
 exactly.  The array is either original itself, or a
 copy whose first original.length bytes are equal to
 original.
public static boolean equals(byte[] b1,
                             byte[] b2)
bytes contain the same
 contents.
b1 - The first arrayb2 - The second array
true if both arrays are null, both
 empty, or both of the same length with equal contents.
public static String print_bytes(byte[] data,
                                 int offset,
                                 int length)
String representation for the specified array of
 bytes.  Print each byte as two hexadecimal
 digits.
data - The array to printoffset - the start offset in datalength - the number of bytes to print
public static String print_bytes_exact(byte[] data,
                                       int offset,
                                       int length)
public static String print_bytes(byte[] data)
  | 
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||