Java Utililty Methods Dump Byte Array

List of utility methods to do Dump Byte Array

Description

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

Method

voiddump(byte[] buffer, int start, int size, PrintStream out)
Prints hex dump of part of byte array to specified stream
StringBuffer sb = new StringBuffer();
int pos = 0;
for (int i = 0; i < size / 16; i++) {
    _dump(buffer, start + pos, 16, out);
    pos += 16;
    out.println();
_dump(buffer, start + pos, size - pos, out);
...
voiddump(byte[] data, OutputStream out, boolean closeOutput)
Dump all data in buffer to output stream.
try {
    out.write(data, 0, data.length);
} finally {
    if (closeOutput) {
        out.close();
voiddump(final byte[] b, final PrintStream out)
dump
for (int i = 0; i < b.length; ++i) {
    if (i % 16 == 0) {
        out.print(Integer.toHexString(i & 0xFFFF | 0x10000).substring(1, 5) + " - ");
    out.print(Integer.toHexString(b[i] & 0xFF | 0x100).substring(1, 3) + ' ');
    if (i % 16 == 15 || i == b.length - 1) {
        int j;
        for (j = 16 - i % 16; j > 1; --j) {
...
voiddump(PrintStream printer, byte[] buffer, int offset, int count)
Dumps a buffer in printable form.
if (count == 0) {
    return;
final int upper_bound = offset + (count / 8 + 1) * 8;
int i = offset;
StringBuffer str = new StringBuffer();
while (i <= upper_bound) {
    int j;
...
voiddumpBuffer(final PrintStream out, final String label, final byte[] b)
dump Buffer
dumpBuffer(out, label, b, 0, b.length);
StringdumpByteArray(byte[] byteArray)
creates a nice hex-dump of the byte array
if (byteArray == null) {
    return "null";
return dumpInputStream(new ByteArrayInputStream(byteArray));
StringdumpByteArray(byte[] bytes)
dump Byte Array
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
    byte b = bytes[i];
    int iVal = b & 0xFF;
    int byteN = Integer.parseInt(Integer.toBinaryString(iVal));
    sb.append(String.format("%1$02d: %2$08d %3$1c %3$d\n", i, byteN, iVal));
return sb.toString();
...
voiddumpBytes(PrintStream printStream, byte bytes[])
dump Bytes
for (int i = 0; i < bytes.length; i++) {
    if (i % 16 == 0)
        printStream.printf("%1$06X:", i);
    printStream.print(' ');
    if (bytes[i] < 32 || bytes[i] >= 127)
        printStream.print(' ');
    else
        printStream.print((char) bytes[i]);
...
voiddumpBytesAsString(ByteArrayOutputStream baos)
dump Bytes As String
byte b[] = baos.toByteArray();
for (byte i : b) {
    System.out.print((char) i);
System.out.println();
voiddumpBytesToFile(byte[] bytes, String outputFile)
dump Bytes To File
try {
    BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile));
    for (int i = 0; i < bytes.length; ++i) {
        bw.write(getByteAsAscii(bytes[i]));
        if ((i + 1) % 16 == 0) {
            bw.write("\n");
    bw.close();
} catch (IOException e) {
    e.printStackTrace();