public class HexDump extends Object
This output consists of the following three pieces, two of which are optional:
Constructor and Description |
---|
HexDump()
Convenience constructor, which emits 78-character-wide lines with
the following characteristics:
Shows offset, using 8-char wide counter followed by 2 chars
16 bytes per line
Shows characters, limited to ASCII, with replacement by spaces,
preceeded by 4 spaces
|
HexDump(int bytesPerLine,
boolean showOffset,
int offsetWidth,
int spacesAfterOffset,
boolean showChars,
int spacesBeforeChars,
boolean replaceNonAscii,
char replacement)
Base constructor, with all sorts of options.
|
Modifier and Type | Method and Description |
---|---|
Iterator<String> |
iterator(byte[] buf)
Creates an iterator over the entire passed buffer, where each call
to
next returns a line of output. |
Iterator<String> |
iterator(byte[] buf,
int off,
int len)
Creates an iterator over a portion of the passed buffer, where each
call to
next returns a line of output. |
void |
setOffset(int value)
Resets the offset counter to a specified value.
|
String |
stringValue(byte[] buf)
Returns a string containing the a dump of the entire passed
buffer, with newlines separating each line of output.
|
String |
stringValue(byte[] buf,
int off,
int len)
Returns a string containing the a dump of the specified portion
of a passed buffer, with newlines separating each line of output.
|
void |
write(PrintWriter out,
byte[] buf)
Writes an entire buffer to the specified PrintWriter, as separate
lines of output.
|
void |
write(PrintWriter out,
byte[] buf,
int off,
int len)
Writes a portion of the passed buffer to the specified PrintWriter,
as separate lines of output.
|
public HexDump(int bytesPerLine, boolean showOffset, int offsetWidth, int spacesAfterOffset, boolean showChars, int spacesBeforeChars, boolean replaceNonAscii, char replacement)
bytesPerLine
- The number of bytes that will be dumped per
"line" (aka iteration) of output.showOffset
- If true
, the output lines will
start with a hex counter showing position of
the bytes in that line, relative to all bytes
dumped by this object.offsetWidth
- Number of characters for offset field. The
actual offset will be trimmed or left-zero-
padded to this size.spacesAfterOffset
- Number of spaces to insert between offset
field (if it's displayed) and hex bytes.showChars
- If true
, the hex dump will be
followed by the characters represented by
those bytes.spacesBeforeChars
- If showing characters, the number of spaces
inserted between the hex dump and characters.replaceNonAscii
- If true
, only bytes between 32
and 126 will be displayed in the character
output; all others will be replaced.replacement
- The character used to replace non-ASCII or
non-printable characters. May be '\0',
which may lead to ugly output.public HexDump()
public void setOffset(int value)
public Iterator<String> iterator(byte[] buf)
next
returns a line of output.public Iterator<String> iterator(byte[] buf, int off, int len)
next
returns a line of output.public String stringValue(byte[] buf)
public String stringValue(byte[] buf, int off, int len)
public void write(PrintWriter out, byte[] buf)
Caller is responsible for setting auto-flush if needed, as well as selecting an appropriate character set if using character displays (picking UTF-8 is a bad idea when outputting raw characters).
public void write(PrintWriter out, byte[] buf, int off, int len)
Caller is responsible for setting auto-flush if needed, as well as selecting an appropriate character set if using character displays (picking UTF-8 is a bad idea when outputting raw characters).