Class ByteUtils


  • public final class ByteUtils
    extends java.lang.Object
    Utilities for byte process
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ByteUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void byte2hex​(byte b, java.lang.StringBuffer buf)  
      static void checkKey​(byte[] keyBytes)  
      static void checkKey​(java.lang.String key)  
      (package private) static void getBytes​(int i, int index, byte[] buf)
      Places characters representing the integer i into the character array buf.
      static void getBytes​(long i, int index, byte[] buf)  
      static byte[] getBytes​(java.lang.String k)  
      static java.lang.String getString​(byte[] bytes)  
      static byte int0​(int x)  
      static byte int1​(int x)  
      static byte int2​(int x)  
      static void int2hex​(int a, java.lang.StringBuffer str)  
      static byte int3​(int x)  
      static boolean isNumber​(java.lang.String string)  
      static boolean isValidString​(java.lang.String s)  
      static byte long0​(long x)  
      static byte long1​(long x)  
      static byte long2​(long x)  
      static byte long3​(long x)  
      static byte long4​(long x)  
      static byte long5​(long x)  
      static byte long6​(long x)  
      static byte long7​(long x)  
      static java.lang.String nextLine​(java.nio.ByteBuffer buffer)
      Read next line from ByteBuffer
      static int normalizeCapacity​(int requestedCapacity)  
      static int setArguments​(byte[] bb, int index, java.lang.Object... args)  
      static void setArguments​(IoBuffer bb, java.lang.Object... args)  
      static void setProtocol​(Protocol protocol)  
      static byte short0​(short x)  
      static byte short1​(short x)  
      static void short2hex​(int a, java.lang.StringBuffer str)  
      static boolean stepBuffer​(java.nio.ByteBuffer buffer, int remaining)  
      static int stringSize​(int x)  
      static int stringSize​(long x)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • log

        public static final org.slf4j.Logger log
      • DEFAULT_CHARSET_NAME

        public static final java.lang.String DEFAULT_CHARSET_NAME
        See Also:
        Constant Field Values
      • DEFAULT_CHARSET

        public static final java.nio.charset.Charset DEFAULT_CHARSET
      • SPLIT

        public static final java.nio.ByteBuffer SPLIT
      • ENABLE_FAST_STRING_ENCODER

        public static final boolean ENABLE_FAST_STRING_ENCODER
      • testing

        public static boolean testing
        if it is testing,check key argument even if use binary protocol. The user must never change this value at all.
      • memcachedProtocol

        private static Protocol memcachedProtocol
      • maxKeyLength

        private static int maxKeyLength
      • digits

        static final byte[] digits
        All possible chars for representing a number as a String
      • DigitTens

        static final byte[] DigitTens
      • DigitOnes

        static final byte[] DigitOnes
      • sizeTable

        static final int[] sizeTable
      • byte_len_array

        static final int[] byte_len_array
    • Constructor Detail

      • ByteUtils

        private ByteUtils()
    • Method Detail

      • isValidString

        public static boolean isValidString​(java.lang.String s)
      • isNumber

        public static boolean isNumber​(java.lang.String string)
      • getBytes

        public static final byte[] getBytes​(java.lang.String k)
      • setArguments

        public static final void setArguments​(IoBuffer bb,
                                              java.lang.Object... args)
      • setArguments

        public static final int setArguments​(byte[] bb,
                                             int index,
                                             java.lang.Object... args)
      • checkKey

        public static final void checkKey​(byte[] keyBytes)
      • checkKey

        public static final void checkKey​(java.lang.String key)
      • setProtocol

        public static void setProtocol​(Protocol protocol)
      • normalizeCapacity

        public static final int normalizeCapacity​(int requestedCapacity)
      • stepBuffer

        public static final boolean stepBuffer​(java.nio.ByteBuffer buffer,
                                               int remaining)
      • nextLine

        public static final java.lang.String nextLine​(java.nio.ByteBuffer buffer)
        Read next line from ByteBuffer
        Parameters:
        buffer -
        Returns:
      • getString

        public static java.lang.String getString​(byte[] bytes)
      • byte2hex

        public static void byte2hex​(byte b,
                                    java.lang.StringBuffer buf)
      • int2hex

        public static void int2hex​(int a,
                                   java.lang.StringBuffer str)
      • short2hex

        public static void short2hex​(int a,
                                     java.lang.StringBuffer str)
      • getBytes

        public static void getBytes​(long i,
                                    int index,
                                    byte[] buf)
      • getBytes

        static void getBytes​(int i,
                             int index,
                             byte[] buf)
        Places characters representing the integer i into the character array buf. The characters are placed into the buffer backwards starting with the least significant digit at the specified index (exclusive), and working backwards from there. Will fail if i == Integer.MIN_VALUE
      • stringSize

        public static final int stringSize​(int x)
      • stringSize

        public static final int stringSize​(long x)
      • int3

        public static byte int3​(int x)
      • int2

        public static byte int2​(int x)
      • int1

        public static byte int1​(int x)
      • int0

        public static byte int0​(int x)
      • short1

        public static byte short1​(short x)
      • short0

        public static byte short0​(short x)
      • long7

        public static byte long7​(long x)
      • long6

        public static byte long6​(long x)
      • long5

        public static byte long5​(long x)
      • long4

        public static byte long4​(long x)
      • long3

        public static byte long3​(long x)
      • long2

        public static byte long2​(long x)
      • long1

        public static byte long1​(long x)
      • long0

        public static byte long0​(long x)