Java Utililty Methods Array Dump

List of utility methods to do Array Dump

Description

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

Method

StringdumpHexString(final byte[] array)
dump Hex String
return dumpHexString(array, 0, array.length);
voiddumpInt(String name, int[] src)
dump Int
System.out.println(String.format("%s: [", name));
int col = 0;
for (int i = 0; i < src.length; ++i) {
    if (col == 0) {
        System.out.format(" ");
    System.out.format(" %08x", src[i]);
    col = (col + 1) % 8;
...
StringdumpIntArray(int[] A, int n)
dump Int Array
String str = "";
for (int i = 0; i < n; i++)
    str += " " + A[i];
return str;
voiddumpIntArray(int[] data, String label)
dump Int Array
System.out.print(label);
for (int i = 0; i < data.length; ++i) {
    if (i % 6 == 0) {
        System.out.println();
    System.out.format(" %1$11d", data[i]);
System.out.println();
...
voiddumpMatrix(byte[] matrix, int numDataUnits, int numAllUnits)
dump Matrix
for (int i = 0; i < numDataUnits; i++) {
    for (int j = 0; j < numAllUnits; j++) {
        System.out.print(" ");
        System.out.print(0xff & matrix[i * numAllUnits + j]);
    System.out.println();
StringdumpMessage(byte b[])
dump Message
return dumpMessage(b, 0, b.length);
voiddumpOctets(byte[] data)
dump Octets
final int inc = 8;
for (int i = 0; i < data.length; i += inc) {
    for (int j = i; j - i < inc; j++) {
        if (j < data.length) {
            int n = data[j];
            if (n < 0) {
                n += 256;
            String s;
            if (n < 10) {
                s = "  " + n;
            } else if (n < 100) {
                s = " " + n;
            } else {
                s = "" + n;
            System.out.print(s + " ");
        } else {
            System.out.print("    ");
    System.out.print('"');
    for (int j = i; j < data.length && j - i < inc; j++) {
        if (data[j] >= (byte) 32 && data[j] < (byte) 127) {
            System.out.print((char) data[j]);
        } else {
            System.out.print('.');
    System.out.println('"');
voiddumpPosition(long[] position)
dump Position
for (long p : position) {
    System.out.print(" " + p);
System.out.println();
StringdumpStackTrace(StackTraceElement[] elements)
dump Stack Trace
String dump = "";
for (StackTraceElement element : elements) {
    dump += element.toString() + "\n";
return dump;
StringdumpString(byte[] b)
converts a byte array to printable characters
StringBuffer d = new StringBuffer(b.length * 2);
for (int i = 0; i < b.length; i++) {
    char c = (char) b[i];
    if (Character.isISOControl(c)) {
        switch (c) {
        case '\r':
            d.append("{CR}");
            break;
...