Java Array Dump dumpString(byte[] b)

Here you can find the source of dumpString(byte[] b)

Description

converts a byte array to printable characters

License

Open Source License

Parameter

Parameter Description
b - byte array

Return

String representation

Declaration

public static String dumpString(byte[] b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  w  ww.  j  a v  a  2s  . c  om
     * converts a byte array to printable characters
     *
     * @param b - byte array
     * @return String representation
     */
    public static String dumpString(byte[] b) {
        StringBuilder d = new StringBuilder(b.length * 2);
        for (byte aB : b) {
            char c = (char) aB;
            if (Character.isISOControl(c)) {
                switch (c) {
                case '\r':
                    d.append("{CR}");
                    break;
                case '\n':
                    d.append("{LF}");
                    break;
                case '\000':
                    d.append("{NULL}");
                    break;
                default:
                    char hi = Character.forDigit((aB >> 4) & 0x0F, 16);
                    char lo = Character.forDigit(aB & 0x0F, 16);
                    d.append('[').append(Character.toUpperCase(hi)).append(Character.toUpperCase(lo)).append(']');
                    break;
                }
            } else
                d.append(c);

        }
        return d.toString();
    }
}

Related

  1. dumpMessage(byte b[])
  2. dumpOctets(byte[] data)
  3. dumpPosition(long[] position)
  4. dumpStackTrace(StackTraceElement[] elements)
  5. dumpString(byte[] b)
  6. dumpString(byte[] data)
  7. dumpString(byte[] data)
  8. dumpString(byte[] data)
  9. dumpTo(byte[] array, int length)