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 boolean
hasCommonPrefix
(byte[] bytes1, byte[] bytes2, int prefixSize) Return whetherbytes1
andbytes2
each begin with a common prefix with a size of at leastprefixSize
.static String
loggable
(byte[] bytes) Creates a human-readable representation ofbytes
for logging purposes.static String
toHexString
(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 digitsA
throughF
, so the returned string will match regex([0-9A-F])*
.- Parameters:
bytes
- abyte
array- Returns:
- a hex representation of
bytes
-
loggable
Creates a human-readable representation ofbytes
for 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.- Parameters:
bytes
- abyte
array- 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 returnnull
if the providedloggableBytes
array 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 whetherbytes1
andbytes2
each 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
prefixSize
bytes frombytes1
match the firstprefixSize
bytes frombytes2
-