Here you can find the source of dumpAsHex(byte[] src, int length)
public static String dumpAsHex(byte[] src, int length)
//package com.java2s; public class Main { public static String dumpAsHex(byte[] src, int length) { StringBuilder out = new StringBuilder(length * 4); int p = 0; int rows = length / 8; for (int i = 0; (i < rows) && (p < length); i++) { int ptemp = p; for (int j = 0; j < 8; j++) { String hexVal = Integer.toHexString(src[ptemp] & 0xff); if (hexVal.length() == 1) out.append('0'); out.append(hexVal).append(' '); ptemp++;/*from ww w . ja va 2 s . c o m*/ } out.append(" "); for (int j = 0; j < 8; j++) { int b = 0xff & src[p]; if (b > 32 && b < 127) { out.append((char) b).append(' '); } else { out.append(". "); } p++; } out.append('\n'); } int n = 0; for (int i = p; i < length; i++) { String hexVal = Integer.toHexString(src[i] & 0xff); if (hexVal.length() == 1) out.append('0'); out.append(hexVal).append(' '); n++; } for (int i = n; i < 8; i++) { out.append(" "); } out.append(" "); for (int i = p; i < length; i++) { int b = 0xff & src[i]; if (b > 32 && b < 127) { out.append((char) b).append(' '); } else { out.append(". "); } } out.append('\n'); return out.toString(); } public static String toString(byte[] bytes) { if (bytes == null || bytes.length == 0) { return ""; } StringBuffer buffer = new StringBuffer(); for (byte byt : bytes) { buffer.append((char) byt); } return buffer.toString(); } }