org.apache.hadoop.hbase.util
Class Bytes

java.lang.Object
  extended by org.apache.hadoop.hbase.util.Bytes

public class Bytes
extends Object


Field Summary
static Comparator<byte[]> BYTES_COMPARATOR
          Pass this to TreeMaps where byte [] are keys.
static int SIZEOF_INT
          Size of int in bytes
static int SIZEOF_LONG
          Size of long in bytes
 
Constructor Summary
Bytes()
           
 
Method Summary
static byte[] add(byte[] a, byte[] b)
           
static byte[] add(byte[] a, byte[] b, byte[] c)
           
static int compareTo(byte[] left, byte[] right)
           
static int compareTo(byte[] left, int leftOffset, int leftLength, byte[] right, int rightOffset, int rightLength)
           
static boolean equals(byte[] left, byte[] right)
           
static int hashCode(byte[] b)
           
static int hashCode(byte[] b, int length)
           
static Integer mapKey(byte[] b)
           
static Integer mapKey(byte[] b, int length)
           
static byte[] readByteArray(DataInput in)
           
static byte[][] toByteArrays(byte[] column)
           
static byte[][] toByteArrays(String column)
           
static byte[][] toByteArrays(String[] t)
           
static byte[][] toByteArrays(org.apache.hadoop.io.Text[] t)
           
static byte[] toBytes(int val)
          Convert an int value to a byte array
static byte[] toBytes(long val)
          Convert a long value to a byte array
static byte[] toBytes(String s)
          Converts a string to a UTF-8 byte array.
static int toInt(byte[] bytes)
          Converts a byte array to a long value
static long toLong(byte[] bytes)
          Converts a byte array to a long value
static String toString(byte[] b)
           
static void writeByteArray(DataOutput out, byte[] b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZEOF_LONG

public static final int SIZEOF_LONG
Size of long in bytes

See Also:
Constant Field Values

SIZEOF_INT

public static final int SIZEOF_INT
Size of int in bytes

See Also:
Constant Field Values

BYTES_COMPARATOR

public static Comparator<byte[]> BYTES_COMPARATOR
Pass this to TreeMaps where byte [] are keys.

Constructor Detail

Bytes

public Bytes()
Method Detail

readByteArray

public static byte[] readByteArray(DataInput in)
                            throws IOException
Parameters:
in - Input to read from.
Returns:
byte array read off in
Throws:
IOException

writeByteArray

public static void writeByteArray(DataOutput out,
                                  byte[] b)
                           throws IOException
Parameters:
out -
b -
Throws:
IOException

toString

public static String toString(byte[] b)
Parameters:
b - Presumed UTF-8 encoded byte array.
Returns:
String made from b

toBytes

public static byte[] toBytes(String s)
Converts a string to a UTF-8 byte array.

Parameters:
s -
Returns:
the byte array

toBytes

public static byte[] toBytes(long val)
Convert a long value to a byte array

Parameters:
val -
Returns:
the byte array

toLong

public static long toLong(byte[] bytes)
Converts a byte array to a long value

Parameters:
bytes -
Returns:
the long value

toBytes

public static byte[] toBytes(int val)
Convert an int value to a byte array

Parameters:
val -
Returns:
the byte array

toInt

public static int toInt(byte[] bytes)
Converts a byte array to a long value

Parameters:
bytes -
Returns:
the long value

compareTo

public static int compareTo(byte[] left,
                            byte[] right)
Parameters:
left -
right -
Returns:
0 if equal, < 0 if left is less than right, etc.

compareTo

public static int compareTo(byte[] left,
                            int leftOffset,
                            int leftLength,
                            byte[] right,
                            int rightOffset,
                            int rightLength)
Parameters:
left -
right -
leftOffset - Where to start comparing in the left buffer
rightOffset - Where to start comparing in the right buffer
leftLength - How much to compare from the left buffer
rightLength - How much to compare from the right buffer
Returns:
0 if equal, < 0 if left is less than right, etc.

equals

public static boolean equals(byte[] left,
                             byte[] right)
Parameters:
left -
right -
Returns:
True if equal

hashCode

public static int hashCode(byte[] b)
Parameters:
b -
Returns:
Runs WritableComparator.hashBytes(byte[], int) on the passed in array. This method is what Text and ImmutableBytesWritable use calculating hash code.

hashCode

public static int hashCode(byte[] b,
                           int length)
Parameters:
b -
Returns:
Runs WritableComparator.hashBytes(byte[], int) on the passed in array. This method is what Text and ImmutableBytesWritable use calculating hash code.

mapKey

public static Integer mapKey(byte[] b)
Parameters:
b -
Returns:
A hash of b as an Integer that can be used as key in Maps.

mapKey

public static Integer mapKey(byte[] b,
                             int length)
Parameters:
b -
Returns:
A hash of b as an Integer that can be used as key in Maps.

add

public static byte[] add(byte[] a,
                         byte[] b)
Parameters:
a -
b -
Returns:
New array that has a in lower half and b in upper half.

add

public static byte[] add(byte[] a,
                         byte[] b,
                         byte[] c)
Parameters:
a -
b -
c -
Returns:
New array made from a, b and c

toByteArrays

public static byte[][] toByteArrays(org.apache.hadoop.io.Text[] t)
Parameters:
t -
Returns:
Array of byte arrays made from passed array of Text

toByteArrays

public static byte[][] toByteArrays(String[] t)
Parameters:
t -
Returns:
Array of byte arrays made from passed array of Text

toByteArrays

public static byte[][] toByteArrays(String column)
Parameters:
column -
Returns:
A byte array of a byte array where first and only entry is column

toByteArrays

public static byte[][] toByteArrays(byte[] column)
Parameters:
column -
Returns:
A byte array of a byte array where first and only entry is column


Copyright © 2008 The Apache Software Foundation