Package org.agrona

Class PrintBufferUtil


  • public final class PrintBufferUtil
    extends java.lang.Object
    Useful utils to hex dump the Agrona's buffers.

    This is code adapted from the Netty project adopted to support DirectBuffer.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  PrintBufferUtil.HexUtil  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String[] BYTE2HEX_PAD  
      private static java.lang.String EMPTY_STRING  
      private static java.lang.String NEWLINE  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private PrintBufferUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void appendPrettyHexDump​(java.lang.StringBuilder dump, DirectBuffer buffer)
      Appends the prettified multi-line hexadecimal dump of the specified DirectBuffer to the specified StringBuilder that is easy to read by humans.
      static void appendPrettyHexDump​(java.lang.StringBuilder dump, DirectBuffer buffer, int offset, int length)
      Appends the prettified multi-line hexadecimal dump of the specified DirectBuffer to the specified StringBuilder that is easy to read by humans, starting at the given offset using the given length.
      static java.lang.String byteToHexStringPadded​(int value)
      Converts the specified byte value into a 2-digit hexadecimal integer.
      static java.lang.String hexDump​(byte[] array)
      Returns a hex dump of the specified byte array.
      static java.lang.String hexDump​(byte[] array, int fromIndex, int length)
      Returns a hex dump of the specified byte array's subregion.
      static java.lang.String hexDump​(DirectBuffer buffer)
      Returns a hex dump of the specified buffer's readable bytes.
      static java.lang.String hexDump​(DirectBuffer buffer, int fromIndex, int length)
      Returns a hex dump of the specified buffer's subregion.
      static java.lang.String prettyHexDump​(DirectBuffer buffer)
      Returns a hexadecimal dump of the specified DirectBuffer that is easy to read by humans.
      static java.lang.String prettyHexDump​(DirectBuffer buffer, int offset, int length)
      Returns a hexadecimal dump of the specified DirectBuffer that is easy to read by humans, starting at the given offset using the given length.
      • Methods inherited from class java.lang.Object

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

      • NEWLINE

        private static final java.lang.String NEWLINE
      • BYTE2HEX_PAD

        private static final java.lang.String[] BYTE2HEX_PAD
    • Constructor Detail

      • PrintBufferUtil

        private PrintBufferUtil()
    • Method Detail

      • hexDump

        public static java.lang.String hexDump​(DirectBuffer buffer)
        Returns a hex dump of the specified buffer's readable bytes.
        Parameters:
        buffer - dumped buffer.
        Returns:
        hex dump in a string representation.
      • hexDump

        public static java.lang.String hexDump​(DirectBuffer buffer,
                                               int fromIndex,
                                               int length)
        Returns a hex dump of the specified buffer's subregion.
        Parameters:
        buffer - dumped buffer.
        fromIndex - where should we start to print.
        length - how much should we print.
        Returns:
        hex dump in a string representation.
      • hexDump

        public static java.lang.String hexDump​(byte[] array)
        Returns a hex dump of the specified byte array.
        Parameters:
        array - dumped array.
        Returns:
        hex dump in a string representation.
      • hexDump

        public static java.lang.String hexDump​(byte[] array,
                                               int fromIndex,
                                               int length)
        Returns a hex dump of the specified byte array's subregion.
        Parameters:
        array - dumped array.
        fromIndex - where should we start to print.
        length - how much should we print.
        Returns:
        hex dump in a string representation.
      • prettyHexDump

        public static java.lang.String prettyHexDump​(DirectBuffer buffer)
        Returns a hexadecimal dump of the specified DirectBuffer that is easy to read by humans.
        Parameters:
        buffer - dumped buffer.
        Returns:
        pretty hex dump in a string representation.
      • prettyHexDump

        public static java.lang.String prettyHexDump​(DirectBuffer buffer,
                                                     int offset,
                                                     int length)
        Returns a hexadecimal dump of the specified DirectBuffer that is easy to read by humans, starting at the given offset using the given length.
        Parameters:
        buffer - dumped buffer.
        offset - where should we start to print.
        length - how much should we print.
        Returns:
        pretty hex dump in a string representation.
      • appendPrettyHexDump

        public static void appendPrettyHexDump​(java.lang.StringBuilder dump,
                                               DirectBuffer buffer)
        Appends the prettified multi-line hexadecimal dump of the specified DirectBuffer to the specified StringBuilder that is easy to read by humans.
        Parameters:
        dump - where should we append string representation of the buffer.
        buffer - dumped buffer.
      • appendPrettyHexDump

        public static void appendPrettyHexDump​(java.lang.StringBuilder dump,
                                               DirectBuffer buffer,
                                               int offset,
                                               int length)
        Appends the prettified multi-line hexadecimal dump of the specified DirectBuffer to the specified StringBuilder that is easy to read by humans, starting at the given offset using the given length.
        Parameters:
        dump - where should we append string representation of the buffer.
        buffer - dumped buffer.
        offset - where should we start to print.
        length - how much should we print.
      • byteToHexStringPadded

        public static java.lang.String byteToHexStringPadded​(int value)
        Converts the specified byte value into a 2-digit hexadecimal integer.
        Parameters:
        value - converted value.
        Returns:
        hex representation of the value.