Class ByteArrayUtil2

java.lang.Object
com.apple.foundationdb.tuple.ByteArrayUtil2

@API(UNSTABLE) public class ByteArrayUtil2 extends Object
Helper methods in the spirit of ByteArrayUtil.
  • Method Details

    • toHexString

      @Nullable public static String toHexString(@Nullable byte[] bytes)
      Create a base-16 representation of the give byte array. This uses upper case letters for hex digits A through F, so the returned string will match regex ([0-9A-F])*.
      Parameters:
      bytes - a byte array
      Returns:
      a hex representation of bytes
    • loggable

      @API(UNSTABLE) @Nullable public static String loggable(@Nullable byte[] bytes)
      Creates a human-readable representation of bytes for logging purposes. This differs from ByteArrayUtil.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 - a byte array
      Returns:
      a hex representation of bytes
      See Also:
    • unprint

      @API(UNSTABLE) @Nullable public static byte[] unprint(@Nullable String loggedBytes)
      Construct a byte array from a human-readable representation returned by ByteArrayUtil.printable(byte[]) or loggable(byte[]). This will only return null if the provided loggableBytes array is null.
      Parameters:
      loggedBytes - a string representation of a byte array in the format returned by ByteArrayUtil.printable(byte[])
      Returns:
      a byte array parsed from loggedBytes
    • hasCommonPrefix

      public static boolean hasCommonPrefix(@Nonnull byte[] bytes1, @Nonnull byte[] bytes2, int prefixSize)
      Return whether bytes1 and bytes2 each begin with a common prefix with a size of at least prefixSize.
      Parameters:
      bytes1 - one byte array
      bytes2 - another byte array
      prefixSize - a number of bytes
      Returns:
      whether the first prefixSize bytes from bytes1 match the first prefixSize bytes from bytes2