Java Utililty Methods Byte Array Dump

List of utility methods to do Byte Array Dump

Description

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

Method

StringdumpBytes(byte[] byts, int offset, int length)
Get printable representation of bytes in array.
StringBuffer buff = new StringBuffer(length * 3);
for (int i = 0; i < length; i++) {
    buff.append(' ');
    byte byt = byts[offset + i];
    buff.append(s_hexChars.charAt((byt >> 4) & 0xF));
    buff.append(s_hexChars.charAt(byt & 0xF));
return buff.toString();
...
StringdumpBytes(byte[] data)
dump Bytes
StringBuilder sb = new StringBuilder();
int i = 0;
for (byte b : data) {
    i++;
    sb.append(String.valueOf(b));
    if (i < data.length)
        sb.append(", ");
    if ((i % 15) == 0)
...
voiddumpBytes(byte[] data)
dump Bytes
for (int i = 0; data != null && i < data.length; i++) {
    if (i % 8 == 0 && i != 0)
        System.out.println();
    if (i % 8 == 0)
        System.out.printf("%04d:", i);
    System.out.printf(" %3d", ((int) data[i]));
System.out.println();
...
StringdumpBytes(final byte[] bytes)
dump the content of the rawdata, this method is used by finest logging
String result = "";
for (int i = 0; i < bytes.length; i++) {
    result += byteToHexString(bytes[i]).replace("0x", "");
    if (i == bytes.length - 1) {
        break;
    result += ", ";
    if (i % 5 == 4) {
...
voiddumpBytes(String headerStr, byte[] bytes)
Dumps (prints) the byte array.
StringBuffer buf = new StringBuffer(bytes.length);
buf.append("\n");
buf.append(headerStr).append("\n");
buf.append("bytes.length: ").append(bytes.length).append("\n");
int len = bytes.length;
int i = 0;
for (i = 0; i < len; i++) {
    buf.append(toHex(bytes[i]) + " ");
...
voiddumpBytesAsInt(byte[] b)
dump Bytes As Int
int length = b.length;
String comma = "";
for (int i = 0; i < length; i++) {
    System.out.print(comma + (short) b[i]);
    comma = ",";
System.out.println();
StringdumpCodeBytes(byte[] data)
Creates a String which represents the given byte array as if it was declared as Java code.
StringBuilder sb = new StringBuilder();
sb.append("{\n");
for (int blockOfs = 0; blockOfs < data.length; blockOfs += 8) {
    sb.append("/*@0x");
    sb.append(Integer.toHexString(blockOfs));
    sb.append(":*/ ");
    for (int i = 0; i < 8; i++) {
        if (blockOfs + i > data.length)
...
Stringdumphex(byte[] bytes)
dumphex
int bsLen = bytes.length;
String head = "-Location- -0--1--2--3--4--5--6--7--8--9--A--B--C--D--E--F--0--1--2--3--4--5--6--7--8--9--A--B--C--D--E--F- ---ASCII Code---\n";
StringBuilder ret = new StringBuilder(head.length() + bsLen * 3);
ret.append(head);
for (int i = 0; i < bsLen;) {
    ret.append(lpadding(Integer.toHexString(i), 4, "0")).append('(');
    ret.append(lpadding("" + i, 4, "0")).append(") ");
    for (int j = 0; j < 32; j++) {
...
StringdumpHexBytes(byte[] bytes)
Converts a byte array to a string of hex bytes.
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
    sb.append(String.format("%02X", b) + " ");
return sb.toString();
StringdumpHexData(String title, byte[] buf, int numBytes)
This method dumps a byte array as hex characters.
int rows;
int residue;
int i;
int j;
int labelSize;
byte[] rowBuf = new byte[BYTES_PER_ROW + 2];
String[] charBuf = new String[4];
String result = title + " - " + numBytes + " bytes." + LINE_SEPARATOR;
...