|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.hadoop.hbase.util.Bytes
public class Bytes
Utility class that handles byte arrays, conversions to/from other types, comparisons, hash code generation, manufacturing keys for HashMaps or HashSets, etc.
| Nested Class Summary | |
|---|---|
static class |
Bytes.ByteArrayComparator
Byte array comparator class. |
| Field Summary | |
|---|---|
static Comparator<byte[]> |
BYTES_COMPARATOR
Pass this to TreeMaps where byte [] are keys. |
static org.apache.hadoop.io.RawComparator<byte[]> |
BYTES_RAWCOMPARATOR
Use comparing byte arrays, byte-by-byte |
static int |
ESTIMATED_HEAP_TAX
Estimate of size cost to pay beyond payload in jvm for instance of byte []. |
static int |
SIZEOF_BOOLEAN
Size of boolean in bytes |
static int |
SIZEOF_BYTE
Size of byte in bytes |
static int |
SIZEOF_CHAR
Size of char in bytes |
static int |
SIZEOF_DOUBLE
Size of double in bytes |
static int |
SIZEOF_FLOAT
Size of float in bytes |
static int |
SIZEOF_INT
Size of int in bytes |
static int |
SIZEOF_LONG
Size of long in bytes |
static int |
SIZEOF_SHORT
Size of short 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 |
binarySearch(byte[][] arr,
byte[] key,
int offset,
int length,
org.apache.hadoop.io.RawComparator<byte[]> comparator)
Binary search for keys in indexes. |
static long |
bytesToVint(byte[] buffer)
|
static int |
compareTo(byte[] left,
byte[] right)
|
static int |
compareTo(byte[] b1,
int s1,
int l1,
byte[] b2,
int s2,
int l2)
|
static boolean |
equals(byte[] left,
byte[] right)
|
static int |
hashCode(byte[] b)
|
static int |
hashCode(byte[] b,
int length)
|
static byte[] |
head(byte[] a,
int length)
|
static byte[] |
incrementBytes(byte[] value,
long amount)
Bytewise binary increment/deincrement of long contained in byte array on given amount. |
static Integer |
mapKey(byte[] b)
|
static Integer |
mapKey(byte[] b,
int length)
|
static byte[] |
padHead(byte[] a,
int length)
|
static byte[] |
padTail(byte[] a,
int length)
|
static int |
putByte(byte[] bytes,
int offset,
byte b)
Write a single byte out to the specified byte array position. |
static int |
putBytes(byte[] tgtBytes,
int tgtOffset,
byte[] srcBytes,
int srcOffset,
int srcLength)
Put bytes at the specified byte array position. |
static int |
putDouble(byte[] bytes,
int offset,
double d)
|
static int |
putFloat(byte[] bytes,
int offset,
float f)
|
static int |
putInt(byte[] bytes,
int offset,
int val)
Put an int value out to the specified byte array position. |
static int |
putLong(byte[] bytes,
int offset,
long val)
Put a long value out to the specified byte array position. |
static int |
putShort(byte[] bytes,
int offset,
short val)
Put a short value out to the specified byte array position. |
static byte[] |
readByteArray(DataInput in)
Read byte-array written with a WritableableUtils.vint prefix. |
static byte[] |
readByteArrayThrowsRuntime(DataInput in)
Read byte-array written with a WritableableUtils.vint prefix. |
static long |
readVLong(byte[] buffer,
int offset)
Reads a zero-compressed encoded long from input stream and returns it. |
static byte[][] |
split(byte[] a,
byte[] b,
int num)
Split passed range. |
static byte[] |
tail(byte[] a,
int length)
|
static byte |
toBinaryFromHex(byte ch)
Takes a ASCII digit in the range A-F0-9 and returns the corresponding integer/ordinal value. |
static boolean |
toBoolean(byte[] b)
|
static byte[][] |
toByteArrays(byte[] column)
|
static byte[][] |
toByteArrays(String column)
|
static byte[][] |
toByteArrays(String[] t)
|
static byte[] |
toBytes(boolean b)
Convert a boolean to a byte array. |
static byte[] |
toBytes(ByteBuffer bb)
Returns a new byte array, copied from the passed ByteBuffer. |
static byte[] |
toBytes(double d)
|
static byte[] |
toBytes(float f)
|
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(short val)
Convert a short value to a byte array |
static byte[] |
toBytes(String s)
Converts a string to a UTF-8 byte array. |
static byte[] |
toBytesBinary(String in)
|
static double |
toDouble(byte[] bytes)
|
static double |
toDouble(byte[] bytes,
int offset)
|
static float |
toFloat(byte[] bytes)
Presumes float encoded as IEEE 754 floating-point "single format" |
static float |
toFloat(byte[] bytes,
int offset)
Presumes float encoded as IEEE 754 floating-point "single format" |
static int |
toInt(byte[] bytes)
Converts a byte array to an int value |
static int |
toInt(byte[] bytes,
int offset)
Converts a byte array to an int value |
static int |
toInt(byte[] bytes,
int offset,
int length)
Converts a byte array to an int value |
static long |
toLong(byte[] bytes)
Converts a byte array to a long value |
static long |
toLong(byte[] bytes,
int offset)
Converts a byte array to a long value |
static long |
toLong(byte[] bytes,
int offset,
int length)
Converts a byte array to a long value |
static short |
toShort(byte[] bytes)
Converts a byte array to a short value |
static short |
toShort(byte[] bytes,
int offset)
Converts a byte array to a short value |
static short |
toShort(byte[] bytes,
int offset,
int length)
Converts a byte array to a short value |
static String |
toString(byte[] b)
|
static String |
toString(byte[] b,
int off,
int len)
|
static String |
toString(byte[] b1,
String sep,
byte[] b2)
|
static String |
toStringBinary(byte[] b)
|
static String |
toStringBinary(byte[] b,
int off,
int len)
|
static byte[] |
vintToBytes(long vint)
|
static int |
writeByteArray(byte[] tgt,
int tgtOffset,
byte[] src,
int srcOffset,
int srcLength)
Write byte-array from src to tgt with a vint length prefix. |
static void |
writeByteArray(DataOutput out,
byte[] b)
Write byte-array with a WritableableUtils.vint prefix. |
static void |
writeByteArray(DataOutput out,
byte[] b,
int offset,
int length)
Write byte-array to out with a vint length prefix. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int SIZEOF_BOOLEAN
public static final int SIZEOF_BYTE
public static final int SIZEOF_CHAR
public static final int SIZEOF_DOUBLE
public static final int SIZEOF_FLOAT
public static final int SIZEOF_INT
public static final int SIZEOF_LONG
public static final int SIZEOF_SHORT
public static final int ESTIMATED_HEAP_TAX
public static Comparator<byte[]> BYTES_COMPARATOR
public static org.apache.hadoop.io.RawComparator<byte[]> BYTES_RAWCOMPARATOR
| Constructor Detail |
|---|
public Bytes()
| Method Detail |
|---|
public static byte[] readByteArray(DataInput in)
throws IOException
in - Input to read from.
in
IOExceptionpublic static byte[] readByteArrayThrowsRuntime(DataInput in)
in - Input to read from.
in
public static void writeByteArray(DataOutput out,
byte[] b)
throws IOException
out - b -
IOException
public static void writeByteArray(DataOutput out,
byte[] b,
int offset,
int length)
throws IOException
out - b - offset - length -
IOException
public static int writeByteArray(byte[] tgt,
int tgtOffset,
byte[] src,
int srcOffset,
int srcLength)
tgt - tgtOffset - src - srcOffset - srcLength -
public static int putBytes(byte[] tgtBytes,
int tgtOffset,
byte[] srcBytes,
int srcOffset,
int srcLength)
tgtBytes - the byte arraytgtOffset - position in the arraysrcBytes - byte to write outsrcOffset - srcLength -
public static int putByte(byte[] bytes,
int offset,
byte b)
bytes - the byte arrayoffset - position in the arrayb - byte to write out
public static byte[] toBytes(ByteBuffer bb)
bb - A ByteBuffer
public static String toString(byte[] b)
b - Presumed UTF-8 encoded byte array.
b
public static String toString(byte[] b1,
String sep,
byte[] b2)
public static String toString(byte[] b,
int off,
int len)
b - Presumed UTF-8 encoded byte array.off - len -
bpublic static String toStringBinary(byte[] b)
public static String toStringBinary(byte[] b,
int off,
int len)
public static byte toBinaryFromHex(byte ch)
ch - The hex digit.
public static byte[] toBytesBinary(String in)
public static byte[] toBytes(String s)
s -
public static byte[] toBytes(boolean b)
b -
b encoded in a byte array.public static boolean toBoolean(byte[] b)
b -
public static byte[] toBytes(long val)
val -
public static long toLong(byte[] bytes)
bytes -
public static long toLong(byte[] bytes,
int offset)
bytes - offset -
public static long toLong(byte[] bytes,
int offset,
int length)
bytes - offset - length -
public static int putLong(byte[] bytes,
int offset,
long val)
bytes - the byte arrayoffset - position in the arrayval - long to write out
public static float toFloat(byte[] bytes)
bytes -
public static float toFloat(byte[] bytes,
int offset)
bytes - offset -
public static int putFloat(byte[] bytes,
int offset,
float f)
bytes - offset - f -
bytespublic static byte[] toBytes(float f)
f -
public static double toDouble(byte[] bytes)
bytes -
public static double toDouble(byte[] bytes,
int offset)
bytes - offset -
public static int putDouble(byte[] bytes,
int offset,
double d)
bytes - offset - d -
bytespublic static byte[] toBytes(double d)
d -
public static byte[] toBytes(int val)
val -
public static int toInt(byte[] bytes)
bytes -
public static int toInt(byte[] bytes,
int offset)
bytes - offset -
public static int toInt(byte[] bytes,
int offset,
int length)
bytes - offset - length -
public static int putInt(byte[] bytes,
int offset,
int val)
bytes - the byte arrayoffset - position in the arrayval - int to write out
public static byte[] toBytes(short val)
val -
public static short toShort(byte[] bytes)
bytes -
public static short toShort(byte[] bytes,
int offset)
bytes - offset -
public static short toShort(byte[] bytes,
int offset,
int length)
bytes - offset - length -
public static int putShort(byte[] bytes,
int offset,
short val)
bytes - the byte arrayoffset - position in the arrayval - short to write out
public static byte[] vintToBytes(long vint)
vint - Integer to make a vint of.
public static long bytesToVint(byte[] buffer)
buffer -
public static long readVLong(byte[] buffer,
int offset)
throws IOException
buffer - Binary arrayoffset - Offset into array at which vint begins.
IOException
public static int compareTo(byte[] left,
byte[] right)
left - right -
public static int compareTo(byte[] b1,
int s1,
int l1,
byte[] b2,
int s2,
int l2)
b1 - b2 - s1 - Where to start comparing in the left buffers2 - Where to start comparing in the right bufferl1 - How much to compare from the left bufferl2 - How much to compare from the right buffer
public static boolean equals(byte[] left,
byte[] right)
left - right -
public static int hashCode(byte[] b)
b -
WritableComparator.hashBytes(byte[], int) on the
passed in array. This method is what Text and
ImmutableBytesWritable use calculating hash code.
public static int hashCode(byte[] b,
int length)
b - length -
WritableComparator.hashBytes(byte[], int) on the
passed in array. This method is what Text and
ImmutableBytesWritable use calculating hash code.public static Integer mapKey(byte[] b)
b -
b as an Integer that can be used as key in
Maps.
public static Integer mapKey(byte[] b,
int length)
b - length -
b as an Integer that can be used as key in
Maps.
public static byte[] add(byte[] a,
byte[] b)
a - b -
public static byte[] add(byte[] a,
byte[] b,
byte[] c)
a - b - c -
public static byte[] head(byte[] a,
int length)
a - length -
length bytes from a
public static byte[] tail(byte[] a,
int length)
a - length -
length bytes from a
public static byte[] padHead(byte[] a,
int length)
a - length -
a plus length prepended 0 bytes
public static byte[] padTail(byte[] a,
int length)
a - length -
a plus length appended 0 bytes
public static byte[][] split(byte[] a,
byte[] b,
int num)
a - Beginning of rangeb - End of rangenum - Number of times to split range. Pass 1 if you want to split
the range in two; i.e. one split.
public static byte[][] toByteArrays(String[] t)
t -
public static byte[][] toByteArrays(String column)
column -
columnpublic static byte[][] toByteArrays(byte[] column)
column -
column
public static int binarySearch(byte[][] arr,
byte[] key,
int offset,
int length,
org.apache.hadoop.io.RawComparator<byte[]> comparator)
arr - array of byte arrays to search forkey - the key you want to findoffset - the offset in the key you want to findlength - the length of the keycomparator - a comparator to compare.
public static byte[] incrementBytes(byte[] value,
long amount)
throws IOException
value - - array of bytes containing long (length <= SIZEOF_LONG)amount - value will be incremented on (deincremented if negative)
IOException - - if value.length > SIZEOF_LONG
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||