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 bb[])
Dump byte array as hex string.
StringBuffer result = new StringBuffer(bb.length * 4);
String ss;
int c = 8;
int lineCount = bb.length / c;
int t = bb.length % c;
if (t != 0) {
    lineCount++;
for (int i = 0; i < lineCount; i++) {
    result.append(i * c + "\t:");
    int tt = c;
    if (t != 0 && i == lineCount - 1) {
        tt = t;
    char cc[] = new char[tt];
    for (int j = 0; j < tt; j++) {
        ss = "0" + Integer.toHexString(bb[i * c + j]);
        result.append(ss.substring(ss.length() - 2) + ",");
        cc[j] = (char) bb[i * c + j];
    for (int k = 0; k < c - tt; k++) {
        result.append("--,");
    result.append("\t:");
    result.append(cc);
    result.append("\n");
return result.toString();
StringdumpBytes(byte[] a)
dump Bytes
StringBuilder sb = new StringBuilder(a.length * 2);
for (byte b : a)
    sb.append(String.format("%x", b & 0xff));
return sb.toString();
voiddumpBytes(byte[] b)
dump Bytes
for (int i = 0; i < b.length; ++i) {
    if (i % 16 == 0)
        System.err.println("");
    String hex = "0" + Integer.toHexString(b[i]);
    hex = hex.substring(hex.length() - 2);
    System.err.print(hex + " ");
System.err.println("\n");
...
StringdumpBytes(byte[] buffer)
Helper function that dump an array of bytes in hex form
if (buffer == null) {
    return "";
StringBuilder sb = new StringBuilder(2 + buffer.length * 2);
for (byte b : buffer) {
    sb.append("0x").append((char) (HEX_CHAR[(b & 0x00F0) >> 4])).append((char) (HEX_CHAR[b & 0x000F]))
            .append(" ");
return sb.toString();
StringdumpBytes(byte[] buffer)
Get the text representation of the specified byte array.
return dumpBytes(buffer, 0, buffer.length);
StringdumpBytes(byte[] bytes)
Returns heksadesimaalit tavutaulukosta merkkijonona.
int size = bytes.length;
StringBuffer sb = new StringBuffer(size * 2);
String s;
for (int i = 0; i < size; ++i) {
    s = Integer.toHexString(bytes[i]);
    if (s.length() == 8) { 
        sb.append(s.substring(6));
    } else if (s.length() == 2) { 
...
StringdumpBytes(byte[] bytes)
dump Bytes
char[] hexChars = new char[bytes.length * 2];
for (int i = 0; i < bytes.length; i++) {
    int val = bytes[i] & 0xFF;
    hexChars[i * 2] = hexArray[val >>> 4];
    hexChars[i * 2 + 1] = hexArray[val & 0x0F];
return new String(hexChars);
StringdumpBytes(byte[] bytes)
dump Bytes
StringBuffer sb = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
    int unsignedInt = 0xFF & bytes[i];
    if (unsignedInt < 0x10) {
        sb.append("0");
    sb.append(Integer.toHexString(unsignedInt));
return sb.toString();
voiddumpBytes(byte[] bytes, int maxLen)
dump Bytes
for (int i = 0, max = Math.min(maxLen, bytes.length); i < max; i++) {
    System.err.print(" ");
    System.err.print(Integer.toHexString(bytes[i] & 0xff));
System.err.println();
StringdumpBytes(byte[] bytes, int start, int length)
Convert a part of an array of bytes, into a string of space-separated hexadecimal numbers.
This method is proposed as a convenience for debugging purposes.
StringBuilder sb = new StringBuilder();
if (length >= 0) {
    for (int i = start; i < Math.min(bytes.length, start + length); i++) {
        if (i > start)
            sb.append(' ');
        sb.append(toHexString(bytes[i]));
return sb.toString();