Package org.agrona
Class PrintBufferUtil
- java.lang.Object
-
- org.agrona.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 specifiedDirectBuffer
to the specifiedStringBuilder
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 specifiedDirectBuffer
to the specifiedStringBuilder
that is easy to read by humans, starting at the givenoffset
using the givenlength
.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 specifiedDirectBuffer
that is easy to read by humans.static java.lang.String
prettyHexDump(DirectBuffer buffer, int offset, int length)
Returns a hexadecimal dump of the specifiedDirectBuffer
that is easy to read by humans, starting at the givenoffset
using the givenlength
.
-
-
-
Field Detail
-
NEWLINE
private static final java.lang.String NEWLINE
-
EMPTY_STRING
private static final java.lang.String EMPTY_STRING
- See Also:
- Constant Field Values
-
BYTE2HEX_PAD
private static final java.lang.String[] BYTE2HEX_PAD
-
-
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 specifiedDirectBuffer
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 specifiedDirectBuffer
that is easy to read by humans, starting at the givenoffset
using the givenlength
.- 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 specifiedDirectBuffer
to the specifiedStringBuilder
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 specifiedDirectBuffer
to the specifiedStringBuilder
that is easy to read by humans, starting at the givenoffset
using the givenlength
.- 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.
-
-