Class PtBytes


  • public final class PtBytes
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addIfNotEmpty​(com.google.common.base.MoreObjects.ToStringHelper helper, java.lang.String name, byte[] bytes)  
      static int compareTo​(byte[] left, byte[] right)
      Compare two byte arrays.
      static byte[] decodeBase64​(java.lang.String data)  
      static byte[] decodeHexString​(java.lang.String hexString)  
      static java.lang.String encodeBase64String​(byte[] data)  
      static java.lang.String encodeBase64String​(byte[] data, int offset, int length)  
      static java.lang.String encodeHexString​(byte[] name)  
      static byte[] head​(byte[] arr, int length)  
      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.
      static byte[] tail​(byte[] arr, int length)  
      static byte[] toBytes​(long val)
      Convert a long value to a byte array using big-endian.
      static byte[] toBytes​(java.lang.String str)
      Converts a string to a UTF-8 byte array.
      static byte[] toCachedBytes​(java.lang.String str)
      Converts a string to a UTF-8 byte array.
      static long toLong​(byte[] bytes)
      Converts a byte array to a long value.
      static long toLong​(byte[] bytes, int offset)
      Converts a byte array to a long value.
      static java.lang.String toString​(byte[] arr)  
      static java.lang.String toString​(byte[] arr, int off, int len)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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[],​java.lang.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​(java.lang.String str)
        Converts a string to a UTF-8 byte array.
      • toCachedBytes

        public static byte[] toCachedBytes​(java.lang.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 java.lang.String toString​(byte[] arr)
      • toString

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

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

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

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

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

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

        public static byte[] decodeBase64​(java.lang.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