public final class Bytes extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Bytes.ByteMap<V>
A convenient map keyed with a byte array.
|
Modifier and Type | Field and Description |
---|---|
static org.hbase.async.Bytes.MemCmp |
MEMCMP
A singleton
Comparator for non-null byte arrays. |
Modifier and Type | Method and Description |
---|---|
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 byte[] |
get(com.google.protobuf.ByteString buf)
Extracts the byte array from the given
ByteString without copy. |
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.
|
static com.google.protobuf.ByteString |
wrap(byte[] array)
Wraps a byte array in a
ByteString without copying it. |
public static final org.hbase.async.Bytes.MemCmp MEMCMP
Comparator
for non-null
byte arrays.memcmp(byte[], byte[])
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 com.google.protobuf.ByteString wrap(byte[] array)
ByteString
without copying it.array
- A byte array that must be considered read-only from there on.public static byte[] get(com.google.protobuf.ByteString buf)
ByteString
without copy.buf
- A buffer from which to extract the array. This buffer must be
actually an instance of a LiteralByteString
.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).