Class ByteUtil


  • public class ByteUtil
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String NON_ASCII_STRING  
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String bytesToHex​(byte[] bytes)  
      static java.lang.String bytesToHex​(byte[] bytes, int groupSize)  
      static int bytesToInt​(byte[] b)  
      static long bytesToLong​(byte[] b)  
      static java.lang.String byteToChar​(byte value)  
      static long convertTextBytes​(java.lang.String text)  
      static java.lang.String debugByteArray​(byte[] byteArray)
      Simplify reading of a byte array in a programmers understable way
      static void debugFrame​(org.jboss.logging.Logger logger, java.lang.String message, io.netty.buffer.ByteBuf byteIn)  
      static byte[] doubleLongToBytes​(long value1, long value2)  
      static void ensureExactWritable​(io.netty.buffer.ByteBuf buffer, int minWritableBytes)
      This ensure a more exact resizing then ByteBuf.ensureWritable(int), if needed.
      It won't try to trim a large enough buffer.
      static boolean equals​(byte[] left, byte[] right)  
      static boolean equals​(byte[] left, byte[] right, int rightOffset, int rightLength)  
      static boolean equals​(byte[] bytes, io.netty.buffer.ByteBuf byteBuf, int offset, int length)
      Returns true if the SimpleString encoded content into bytes is equals to s, false otherwise.
      static java.lang.String formatGroup​(java.lang.String str, int groupSize, int lineBreak)  
      static java.lang.String getHumanReadableByteCount​(long bytes)  
      static int hashCode​(byte[] bytes)  
      static byte[] hexToBytes​(java.lang.String hexStr)  
      static int intFromBytes​(byte b1, byte b2, byte b3, byte b4)  
      static byte[] intToBytes​(int value)  
      static byte[] longToBytes​(long value)  
      static void longToBytes​(long x, byte[] output, int offset)  
      static java.lang.String maxString​(java.lang.String value, int size)  
      static void outFrame​(org.jboss.logging.Logger logger, java.lang.String message, io.netty.buffer.ByteBuf byteIn, boolean info)  
      static java.lang.String readLine​(ActiveMQBuffer buffer)  
      static java.lang.String toSimpleString​(byte[] bytes)  
      static void zeros​(java.nio.ByteBuffer buffer)
      It zeroes the whole Buffer.capacity() of the given buffer.
      static void zeros​(java.nio.ByteBuffer buffer, int offset, int bytes)
      It zeroes bytes of the given buffer, starting (inclusive) from offset.
      • Methods inherited from class java.lang.Object

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

      • NON_ASCII_STRING

        public static final java.lang.String NON_ASCII_STRING
        See Also:
        Constant Field Values
    • Constructor Detail

      • ByteUtil

        public ByteUtil()
    • Method Detail

      • debugFrame

        public static void debugFrame​(org.jboss.logging.Logger logger,
                                      java.lang.String message,
                                      io.netty.buffer.ByteBuf byteIn)
      • outFrame

        public static void outFrame​(org.jboss.logging.Logger logger,
                                    java.lang.String message,
                                    io.netty.buffer.ByteBuf byteIn,
                                    boolean info)
      • formatGroup

        public static java.lang.String formatGroup​(java.lang.String str,
                                                   int groupSize,
                                                   int lineBreak)
      • maxString

        public static java.lang.String maxString​(java.lang.String value,
                                                 int size)
      • bytesToHex

        public static java.lang.String bytesToHex​(byte[] bytes)
      • debugByteArray

        public static java.lang.String debugByteArray​(byte[] byteArray)
        Simplify reading of a byte array in a programmers understable way
      • byteToChar

        public static java.lang.String byteToChar​(byte value)
      • bytesToHex

        public static java.lang.String bytesToHex​(byte[] bytes,
                                                  int groupSize)
      • toSimpleString

        public static java.lang.String toSimpleString​(byte[] bytes)
      • intToBytes

        public static final byte[] intToBytes​(int value)
      • bytesToInt

        public static int bytesToInt​(byte[] b)
      • bytesToLong

        public static long bytesToLong​(byte[] b)
      • longToBytes

        public static byte[] longToBytes​(long value)
      • longToBytes

        public static void longToBytes​(long x,
                                       byte[] output,
                                       int offset)
      • doubleLongToBytes

        public static byte[] doubleLongToBytes​(long value1,
                                               long value2)
      • hexToBytes

        public static byte[] hexToBytes​(java.lang.String hexStr)
      • readLine

        public static java.lang.String readLine​(ActiveMQBuffer buffer)
      • convertTextBytes

        public static long convertTextBytes​(java.lang.String text)
      • hashCode

        public static int hashCode​(byte[] bytes)
      • equals

        public static boolean equals​(byte[] left,
                                     byte[] right)
      • equals

        public static boolean equals​(byte[] left,
                                     byte[] right,
                                     int rightOffset,
                                     int rightLength)
      • ensureExactWritable

        public static void ensureExactWritable​(io.netty.buffer.ByteBuf buffer,
                                               int minWritableBytes)
        This ensure a more exact resizing then ByteBuf.ensureWritable(int), if needed.
        It won't try to trim a large enough buffer.
      • equals

        public static boolean equals​(byte[] bytes,
                                     io.netty.buffer.ByteBuf byteBuf,
                                     int offset,
                                     int length)
        Returns true if the SimpleString encoded content into bytes is equals to s, false otherwise.

        It assumes that the bytes content is read using SimpleString.readSimpleString(ByteBuf, int) ie starting right after the length field.

      • intFromBytes

        public static int intFromBytes​(byte b1,
                                       byte b2,
                                       byte b3,
                                       byte b4)
      • zeros

        public static void zeros​(java.nio.ByteBuffer buffer)
        It zeroes the whole Buffer.capacity() of the given buffer.
        Throws:
        java.nio.ReadOnlyBufferException - if buffer is read-only
      • zeros

        public static void zeros​(java.nio.ByteBuffer buffer,
                                 int offset,
                                 int bytes)
        It zeroes bytes of the given buffer, starting (inclusive) from offset.
        Throws:
        java.lang.IndexOutOfBoundsException - if offset + bytes > Buffer.capacity() or offset >= Buffer.capacity()
        java.lang.IllegalArgumentException - if offset or capacity are less then 0
        java.nio.ReadOnlyBufferException - if buffer is read-only
      • getHumanReadableByteCount

        public static java.lang.String getHumanReadableByteCount​(long bytes)