Class PrintBufferUtil

java.lang.Object
org.agrona.PrintBufferUtil

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

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

  • Field Details

  • Constructor Details

    • PrintBufferUtil

      private PrintBufferUtil()
  • Method Details

    • hexDump

      public static 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 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 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 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 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 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(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(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 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.