Class PtBytes


  • public final class PtBytes
    extends Object
    • Field Detail

      • EMPTY_BYTE_ARRAY

        public static final byte[] EMPTY_BYTE_ARRAY
      • BYTES_COMPARATOR

        public static final com.google.common.collect.Ordering<byte[]> BYTES_COMPARATOR
      • BYTES_TO_HEX_STRING

        public static final com.google.common.base.Function<byte[],​String> BYTES_TO_HEX_STRING
    • Method Detail

      • toLong

        public static long toLong​(byte[] bytes)
        Converts a byte array to a long value. Reverses toBytes(long)
      • toLong

        public static long toLong​(byte[] bytes,
                                  int offset)
        Converts a byte array to a long value. Assumes there will be SIZEOF_LONG bytes available.
      • toBytes

        public static byte[] toBytes​(long val)
        Convert a long value to a byte array using big-endian.
      • toBytes

        public static byte[] toBytes​(String str)
        Converts a string to a UTF-8 byte array.
      • toCachedBytes

        public static byte[] toCachedBytes​(String str)
        Converts a string to a UTF-8 byte array. This method will cache results and return cached results, so the resulting byte arrays must not be modified.
      • tail

        public static byte[] tail​(byte[] arr,
                                  int length)
      • head

        public static byte[] head​(byte[] arr,
                                  int length)
      • toString

        public static String toString​(byte[] arr)
      • toString

        public static String toString​(byte[] arr,
                                      int off,
                                      int len)
      • encodeHexString

        public static String encodeHexString​(@Nullable
                                             byte[] name)
      • decodeHexString

        public static byte[] decodeHexString​(@Nullable
                                             String hexString)
      • addIfNotEmpty

        public static void addIfNotEmpty​(com.google.common.base.MoreObjects.ToStringHelper helper,
                                         String name,
                                         byte[] bytes)
      • encodeBase64String

        public static String encodeBase64String​(byte[] data)
      • encodeBase64String

        public static String encodeBase64String​(byte[] data,
                                                int offset,
                                                int length)
      • decodeBase64

        public static byte[] decodeBase64​(String data)
      • startsWith

        public static boolean startsWith​(byte[] bytes,
                                         byte[] prefix)
        Return true if the byte array on the right is a prefix of the byte array on the left.
      • compareTo

        public static int compareTo​(byte[] left,
                                    byte[] right)
        Compare two byte arrays.
        Returns:
        0 if equal, < 0 if left is less than right, etc