|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.hbase.async.Bytes
public final class Bytes
Helper functions to manipulate byte arrays.
Nested Class Summary | |
---|---|
static class |
Bytes.ByteMap<V>
A convenient map keyed with a byte array. |
Field Summary | |
---|---|
static org.hbase.async.Bytes.MemCmp |
MEMCMP
A singleton Comparator for non-null byte arrays. |
Method Summary | |
---|---|
static byte[] |
deDup(byte[] old,
byte[] neww)
De-duplicates two byte arrays. |
static boolean |
equals(byte[] a,
byte[] b)
Tests whether two byte arrays have the same contents. |
static byte[] |
fromInt(int n)
Creates a new byte array containing a big-endian 4-byte integer. |
static byte[] |
fromLong(long n)
Creates a new byte array containing a big-endian 8-byte long integer. |
static byte[] |
fromShort(short n)
Creates a new byte array containing a big-endian 2-byte short integer. |
static int |
getInt(byte[] b)
Reads a big-endian 4-byte integer from the begining of the given array. |
static int |
getInt(byte[] b,
int offset)
Reads a big-endian 4-byte integer from an offset in the given array. |
static long |
getLong(byte[] b)
Reads a big-endian 8-byte long from the begining of the given array. |
static long |
getLong(byte[] b,
int offset)
Reads a big-endian 8-byte long from an offset in the given array. |
static short |
getShort(byte[] b)
Reads a big-endian 2-byte short from the begining of the given array. |
static short |
getShort(byte[] b,
int offset)
Reads a big-endian 2-byte short from an offset in the given array. |
static long |
getUnsignedInt(byte[] b)
Reads a big-endian 4-byte unsigned integer from the begining of the given array. |
static long |
getUnsignedInt(byte[] b,
int offset)
Reads a big-endian 4-byte unsigned integer from an offset in the given array. |
static int |
getUnsignedShort(byte[] b)
Reads a big-endian 2-byte unsigned short from the begining of the given array. |
static int |
getUnsignedShort(byte[] b,
int offset)
Reads a big-endian 2-byte unsigned short from an offset in the given array. |
static String |
hex(long v)
Pretty-prints a long into a fixed-width hexadecimal number. |
static byte[] |
ISO88591(String s)
Transforms a string into an ISO-8859-1 encoded byte array. |
static int |
memcmp(byte[] a,
byte[] b)
memcmp in Java, hooray. |
static int |
memcmp(byte[] a,
byte[] b,
int offset,
int length)
memcmp(3) with a given offset and length. |
static int |
memcmpMaybeNull(byte[] a,
byte[] b)
memcmp(3) in Java for possibly null arrays, hooray. |
static String |
pretty(byte[] array)
Pretty-prints a byte array into a human-readable string. |
static String |
pretty(ChannelBuffer buf)
Pretty-prints all the bytes of a buffer into a human-readable string. |
static void |
pretty(StringBuilder outbuf,
byte[] array)
Pretty-prints a byte array into a human-readable output buffer. |
static void |
pretty(StringBuilder outbuf,
byte[][] arrays)
Pretty-prints an array of byte arrays into a human-readable output buffer. |
static void |
setInt(byte[] b,
int n)
Writes a big-endian 4-byte int at the begining of the given array. |
static void |
setInt(byte[] b,
int n,
int offset)
Writes a big-endian 4-byte int at an offset in the given array. |
static void |
setLong(byte[] b,
long n)
Writes a big-endian 8-byte long at the begining of the given array. |
static void |
setLong(byte[] b,
long n,
int offset)
Writes a big-endian 8-byte long at an offset in the given array. |
static void |
setShort(byte[] b,
short n)
Writes a big-endian 2-byte short at the begining of the given array. |
static void |
setShort(byte[] b,
short n,
int offset)
Writes a big-endian 2-byte short at an offset in the given array. |
static byte[] |
UTF8(String s)
Transforms a string into an UTF-8 encoded byte array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final org.hbase.async.Bytes.MemCmp MEMCMP
Comparator
for non-null
byte arrays.
memcmp(byte[], byte[])
Method Detail |
---|
public static short getShort(byte[] b)
b
- The array to read from.
IndexOutOfBoundsException
- if the byte array is too small.public static short getShort(byte[] b, int offset)
b
- The array to read from.offset
- The offset in the array to start reading from.
IndexOutOfBoundsException
- if the byte array is too small.public static int getUnsignedShort(byte[] b)
b
- The array to read from.
IndexOutOfBoundsException
- if the byte array is too small.public static int getUnsignedShort(byte[] b, int offset)
b
- The array to read from.offset
- The offset in the array to start reading from.
IndexOutOfBoundsException
- if the byte array is too small.public static void setShort(byte[] b, short n)
b
- The array to write to.n
- A short integer.
IndexOutOfBoundsException
- if the byte array is too small.public static void setShort(byte[] b, short n, int offset)
b
- The array to write to.offset
- The offset in the array to start writing at.
IndexOutOfBoundsException
- if the byte array is too small.public static byte[] fromShort(short n)
n
- A short integer.
public static int getInt(byte[] b)
b
- The array to read from.
IndexOutOfBoundsException
- if the byte array is too small.public static int getInt(byte[] b, int offset)
b
- The array to read from.offset
- The offset in the array to start reading from.
IndexOutOfBoundsException
- if the byte array is too small.public static long getUnsignedInt(byte[] b)
b
- The array to read from.
IndexOutOfBoundsException
- if the byte array is too small.public static long getUnsignedInt(byte[] b, int offset)
b
- The array to read from.offset
- The offset in the array to start reading from.
IndexOutOfBoundsException
- if the byte array is too small.public static void setInt(byte[] b, int n)
b
- The array to write to.n
- An integer.
IndexOutOfBoundsException
- if the byte array is too small.public static void setInt(byte[] b, int n, int offset)
b
- The array to write to.offset
- The offset in the array to start writing at.
IndexOutOfBoundsException
- if the byte array is too small.public static byte[] fromInt(int n)
n
- An integer.
public static long getLong(byte[] b)
b
- The array to read from.
IndexOutOfBoundsException
- if the byte array is too small.public static long getLong(byte[] b, int offset)
b
- The array to read from.offset
- The offset in the array to start reading from.
IndexOutOfBoundsException
- if the byte array is too small.public static void setLong(byte[] b, long n)
b
- The array to write to.n
- A long integer.
IndexOutOfBoundsException
- if the byte array is too small.public static void setLong(byte[] b, long n, int offset)
b
- The array to write to.offset
- The offset in the array to start writing at.
IndexOutOfBoundsException
- if the byte array is too small.public static byte[] fromLong(long n)
n
- A long integer.
public static byte[] UTF8(String s)
public static byte[] ISO88591(String s)
public static void pretty(StringBuilder outbuf, byte[] array)
outbuf
- The buffer where to write the output.array
- The (possibly null
) array to pretty-print.public static void pretty(StringBuilder outbuf, byte[][] arrays)
outbuf
- The buffer where to write the output.arrays
- The (possibly null
) array of arrays to pretty-print.public static String pretty(byte[] array)
array
- The (possibly null
) array to pretty-print.
public static String hex(long v)
long
into a fixed-width hexadecimal number.
0x0123456789ABCDEF
.public static String pretty(ChannelBuffer buf)
buf
- The (possibly null
) buffer to pretty-print.
public static int memcmp(byte[] a, byte[] b)
memcmp
in Java, hooray.
a
- First non-null
byte array to compare.b
- Second non-null
byte array to compare.
public static int memcmp(byte[] a, byte[] b, int offset, int length)
memcmp(3)
with a given offset and length.
a
- First non-null
byte array to compare.b
- Second non-null
byte array to compare.offset
- The offset at which to start comparing both arrays.length
- The number of bytes to compare.
IndexOutOfBoundsException
- if either array isn't large enough.public static byte[] deDup(byte[] old, byte[] neww)
If two byte arrays have the same contents but are different, this function helps to re-use the old one and discard the new copy.
old
- The existing byte array.neww
- The new byte array we're trying to de-duplicate.
old
if neww
is a different array with the same
contents, otherwise neww
.public static boolean equals(byte[] a, byte[] b)
a
- First non-null
byte array to compare.b
- Second non-null
byte array to compare.
true
if the two arrays are identical,
false
otherwise.public static int memcmpMaybeNull(byte[] a, byte[] b)
memcmp(3)
in Java for possibly null
arrays, hooray.
a
- First possibly null
byte array to compare.b
- Second possibly null
byte array to compare.
null
),
otherwise the difference between the first two different bytes (treated
as unsigned), otherwise the different between their lengths (a null
byte array is considered shorter than an empty byte array).
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |