public class

HexDump

extends Object
java.lang.Object
   ↳ com.ericsson.research.trap.utils.HexDump

Class Overview

Utility class to print out hexadecimal and pretty data, primarily for debug purposes. When printed, the data is shown in a reasonable and understandable format, like the one below.

 54 68 69 73 20 69 73 20 61 6e 20 65 78 61 6d 70 6c 65 20 6f This.is.an.example.o
 66 20 68 65 78 20 64 75 6d 70 69 6e 67 20 73 6f 6d 65 20 62 f.hex.dumping.some.b
 79 74 65 73 2e 2e 2e                                        ytes...
 

Summary

Public Methods
static Object makeStringifyable(byte[] bytes, int start, int width)
Creates a new object with a toString method that will lazily perform a HexDump on the supplied data.
static void printBytes(byte[] bytes, int start, int width)
Prints the supplied bytes as ASCII to System.out.
static void printBytes(byte[] bytes, int start, int width, PrintStream ps)
Prints a set of bytes to a given stream.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static Object makeStringifyable (byte[] bytes, int start, int width)

Creates a new object with a toString method that will lazily perform a HexDump on the supplied data. This can be used when it is not known if the resulting string will be printed, to save on some computation.

Parameters
bytes The bytes to HexDump
start Offset in the bytes to start at.
width Width (in bytes) of the hex dump
Returns
  • An object with a toString() method that returns the hexDump.

public static void printBytes (byte[] bytes, int start, int width)

Prints the supplied bytes as ASCII to System.out.

Parameters
bytes The bytes to print
start Index to start printing from
width Width in bytes

public static void printBytes (byte[] bytes, int start, int width, PrintStream ps)

Prints a set of bytes to a given stream. The output format is the one specified in the class description. Prints the bytes as hex and ascii until the end of the byte array.

Parameters
bytes The source bytes to print.
start The offset to start printing from.
width Width in bytes of the printed output
ps The stream to print to.