String (final byte[] bytes, final int pageSize) { final StringBuilder sb = new StringBuilder(bytes.length * 3); for (int i = 0; i < bytes.length; i++) { final byte b = bytes[i]; final int unsignedByte = Byte.toUnsignedInt(b); if (unsignedByte < 16) {//Integer.toHexString format it single-digit, which ruins blocks alignment sb.append("0"); } sb.append(Integer.toHexString(unsignedByte)); if (i < bytes.length - 1) { if (pageSize > 0 && i % pageSize == pageSize - 1) { sb.append('\n'); } else { sb.append(' '); } } } return sb.toString(); }