public final class ByteUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static Comparator<byte[]> |
COMPARATOR
Comparator that compares two byte arrays lexicographically using unsigned values. |
static byte[] |
EMPTY
An empty byte array.
|
static Converter<byte[],String> |
STRING_CONVERTER
|
| Modifier and Type | Method and Description |
|---|---|
static int |
compare(byte[] b1,
byte[] b2)
Compare two byte arrays lexicographically using unsigned values.
|
static byte[] |
getKeyAfterPrefix(byte[] prefix)
Get the first key that would be greater than the given key in unsigned lexicographic
ordering and that does not have the given key as a prefix.
|
static byte[] |
getNextKey(byte[] key)
Get the next key greater than the given key in unsigned lexicographic ordering.
|
static boolean |
isConsecutive(byte[] key1,
byte[] key2)
Determine whether
key2 is the next key after key1. |
static boolean |
isPrefixOf(byte[] prefix,
byte[] value)
Determine if the first of two
byte[] arrays is a prefix of the second. |
static byte[] |
max(byte[] b1,
byte[] b2)
Determine the larger of two byte arrays when compared lexicographically using unsigned values.
|
static byte[] |
min(byte[] b1,
byte[] b2)
Determine the smaller of two byte arrays when compared lexicographically using unsigned values.
|
static byte[] |
parse(String text)
Decode a hexadecimal
String into a byte[] array. |
static int |
readInt(ByteReader reader)
Read an
int as four big-endian bytes. |
static long |
readLong(ByteReader reader)
Read a
long as eight big-endian bytes. |
static String |
toString(byte[] buf)
Convert a byte array into a string of hex digits, or
"null" if buf is null. |
static void |
writeInt(ByteWriter writer,
int value)
Write an
int as four big-endian bytes. |
static void |
writeLong(ByteWriter writer,
long value)
Write a
long as eight big-endian bytes. |
public static final byte[] EMPTY
COMPARATOR.public static final Comparator<byte[]> COMPARATOR
Comparator that compares two byte arrays lexicographically using unsigned values.public static int compare(byte[] b1,
byte[] b2)
b1 - first byte arrayb2 - second byte arrayb1 < b2, 1 if b1 > b2, or zero if b1 = b2NullPointerException - if b1 or b2 is nullpublic static byte[] min(byte[] b1,
byte[] b2)
b1 - first byte arrayb2 - second byte arrayb1 if b1 <= b2, otherwise b2NullPointerException - if b1 or b2 is nullpublic static byte[] max(byte[] b1,
byte[] b2)
b1 - first byte arrayb2 - second byte arrayb1 if b1 >= b2, otherwise b2NullPointerException - if b1 or b2 is nullpublic static boolean isPrefixOf(byte[] prefix,
byte[] value)
byte[] arrays is a prefix of the second.prefix - prefix to checkvalue - value to check for having prefix as a prefixprefix is a prefix of valueNullPointerException - if prefix or value is nullpublic static byte[] getNextKey(byte[] key)
0x00 byte to the data
contained in the given key.key - previous keykeyNullPointerException - if key is nullpublic static boolean isConsecutive(byte[] key1,
byte[] key2)
key2 is the next key after key1.key1 - first keykey2 - second keykey2 immediately follows key1NullPointerException - if either parameter is nullpublic static byte[] getKeyAfterPrefix(byte[] prefix)
prefix - lower bound prefix keyprefix as a prefixIllegalArgumentException - if prefix has zero lengthIllegalArgumentException - if prefix contains only 0xff bytesNullPointerException - if prefix is nullpublic static String toString(byte[] buf)
"null" if buf is null.buf - bytesbufparse()public static byte[] parse(String text)
String into a byte[] array. The string must have an even
number of digits and contain no other characters (e.g., whitespace).text - string previously encoded by toString(byte[])byte[] decoding of textIllegalArgumentException - if any non-hexadecimal characters are found or the number of characters is oddNullPointerException - if text is nulltoString()public static int readInt(ByteReader reader)
int as four big-endian bytes.reader - inputIndexOutOfBoundsException - if less than four bytes remain in readerNullPointerException - if reader is nullwriteInt()public static void writeInt(ByteWriter writer, int value)
int as four big-endian bytes.writer - byte destinationvalue - value to writeNullPointerException - if writer is nullreadInt()public static long readLong(ByteReader reader)
long as eight big-endian bytes.reader - inputIndexOutOfBoundsException - if less than eight bytes remain in readerwriteLong()public static void writeLong(ByteWriter writer, long value)
long as eight big-endian bytes.writer - byte destinationvalue - value to writeNullPointerException - if writer is nullreadLong()Copyright © 2016. All rights reserved.