Java Utililty Methods Hex Dump

List of utility methods to do Hex Dump

Description

The list of methods to do Hex Dump are organized into topic(s).

Method

voidhexdump(byte[] bytes, OutputStream out)
hexdump
hexdump(bytes, new PrintStream(out));
StringhexDump(byte[] data)
Dumps binary data, presending raw bytes and their character equivalents.
if (data == null) {
    return NULL;
} else {
    StringWriter w = new StringWriter();
    hexDump(0, new PrintWriter(w), data, 0, data.length);
    return w.toString();
voidhexDump(InputStream is, OutputStream os)
Writes a hex dump representation of input data to the output stream.
int offset = 0;
ByteArrayOutputStream hexStream;
ByteArrayOutputStream asciiStream;
while (true) {
    hexStream = new ByteArrayOutputStream();
    asciiStream = new ByteArrayOutputStream();
    int count = getHexSegment(is, hexStream, asciiStream);
    if (count <= 0)
...
inthexDump(InputStream is, PrintStream ps, int maxRead, int bytesPerLine)
hex Dump
int read, chr, i, result;
char[] pad;
StringBuffer left, right;
if (1 > bytesPerLine) {
    bytesPerLine = 1;
left = new StringBuffer();
right = new StringBuffer();
...
voidhexDump(PrintStream out, String s, byte b[], int n)
hex Dump
if (out == null)
    return;
int i;
out.print(s);
for (i = 0; i < n; ++i) {
    int x = b[i];
    if (x < 0)
        x = 256 + x;
...
voidhexDump(String prompt, byte[] bs)
hex Dump
PrintStream ps = new PrintStream(new BufferedOutputStream(System.out, 2048));
ps.printf("%s:", prompt);
for (byte b : bs)
    ps.printf("%02x ", b);
ps.printf("[");
for (byte b : bs)
    ps.printf("%c", Character.isLetterOrDigit(b) ? b : '.');
ps.printf("]\n");
...
voidhexDumpBytes(PrintStream out, long offset, byte[] bytes)
hex Dump Bytes
final int lineWidth = 16;
char[] line = new char[lineWidth * 3];
for (int i = 0; i < bytes.length; i += lineWidth) {
    int len = Math.min(bytes.length - i, 16);
    for (int j = 0; j < len; j++) {
        int value = bytes[i + j] & 0xFF;
        line[j * 3 + 0] = hexArray[value >>> 4];
        line[j * 3 + 1] = hexArray[value & 0x0F];
...