Here you can find the source of dumpString(byte[] b)
Parameter | Description |
---|---|
b | - byte array |
public static String dumpString(byte[] b)
//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(); } }