Package com.apple.foundationdb.tuple
Class ByteArrayUtil2
java.lang.Object
com.apple.foundationdb.tuple.ByteArrayUtil2
Helper methods in the spirit of
ByteArrayUtil.-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanhasCommonPrefix(byte[] bytes1, byte[] bytes2, int prefixSize) Return whetherbytes1andbytes2each begin with a common prefix with a size of at leastprefixSize.static Stringloggable(byte[] bytes) Creates a human-readable representation ofbytesfor logging purposes.static StringtoHexString(byte[] bytes) Create a base-16 representation of the give byte array.static byte[]Construct a byte array from a human-readable representation returned byByteArrayUtil.printable(byte[])orloggable(byte[]).
-
Method Details
-
toHexString
Create a base-16 representation of the give byte array. This uses upper case letters for hex digitsAthroughF, so the returned string will match regex([0-9A-F])*.- Parameters:
bytes- abytearray- Returns:
- a hex representation of
bytes
-
loggable
Creates a human-readable representation ofbytesfor logging purposes. This differs fromByteArrayUtil.printable(byte[])in tha it excludes the=and"characters, which can cause trouble when included as a key or value in log messages with keys and values. For the same purpose,'is escaped as well.- Parameters:
bytes- abytearray- Returns:
- a hex representation of
bytes - See Also:
-
unprint
Construct a byte array from a human-readable representation returned byByteArrayUtil.printable(byte[])orloggable(byte[]). This will only returnnullif the providedloggableBytesarray isnull.- Parameters:
loggedBytes- a string representation of a byte array in the format returned byByteArrayUtil.printable(byte[])- Returns:
- a byte array parsed from
loggedBytes
-
hasCommonPrefix
public static boolean hasCommonPrefix(@Nonnull byte[] bytes1, @Nonnull byte[] bytes2, int prefixSize) Return whetherbytes1andbytes2each begin with a common prefix with a size of at leastprefixSize.- Parameters:
bytes1- one byte arraybytes2- another byte arrayprefixSize- a number of bytes- Returns:
- whether the first
prefixSizebytes frombytes1match the firstprefixSizebytes frombytes2
-