@Test public void testEmpty() { byte[] array = new byte[0]; String str = HexFormat.format(array, array.length); assertEquals("", str); }
public static String format(byte[] array, int len) { StringBuilder buf = new StringBuilder(); int lines = (len + 15) / 16; for (int i = 0; i < lines; i++) { int off = i * 16; buf.append(toHex(off, 4)); buf.append(" "); int bytes = Math.min(16, len - off); int j; for (j = 0; j < bytes; j++) { if (j == 8) buf.append(' '); buf.append(toHex(array[off + j] & 0xff, 2)); buf.append(' '); } for (; j < 16; j++) { if (j == 8) buf.append(' '); buf.append(" "); } buf.append(" "); for (j = 0; j < bytes; j++) { if (j == 8) buf.append(' '); int c = array[off + j] & 0xff; if (c >= 32 && c < 126) { buf.append((char) c); } else { buf.append('.'); } } if (i != (lines - 1)) buf.append('\n'); } return buf.toString(); }
HexFormat { public static String format(byte[] array, int len) { StringBuilder buf = new StringBuilder(); int lines = (len + 15) / 16; for (int i = 0; i < lines; i++) { int off = i * 16; buf.append(toHex(off, 4)); buf.append(" "); int bytes = Math.min(16, len - off); int j; for (j = 0; j < bytes; j++) { if (j == 8) buf.append(' '); buf.append(toHex(array[off + j] & 0xff, 2)); buf.append(' '); } for (; j < 16; j++) { if (j == 8) buf.append(' '); buf.append(" "); } buf.append(" "); for (j = 0; j < bytes; j++) { if (j == 8) buf.append(' '); int c = array[off + j] & 0xff; if (c >= 32 && c < 126) { buf.append((char) c); } else { buf.append('.'); } } if (i != (lines - 1)) buf.append('\n'); } return buf.toString(); } }
HexFormat { public static String format(byte[] array, int len) { StringBuilder buf = new StringBuilder(); int lines = (len + 15) / 16; for (int i = 0; i < lines; i++) { int off = i * 16; buf.append(toHex(off, 4)); buf.append(" "); int bytes = Math.min(16, len - off); int j; for (j = 0; j < bytes; j++) { if (j == 8) buf.append(' '); buf.append(toHex(array[off + j] & 0xff, 2)); buf.append(' '); } for (; j < 16; j++) { if (j == 8) buf.append(' '); buf.append(" "); } buf.append(" "); for (j = 0; j < bytes; j++) { if (j == 8) buf.append(' '); int c = array[off + j] & 0xff; if (c >= 32 && c < 126) { buf.append((char) c); } else { buf.append('.'); } } if (i != (lines - 1)) buf.append('\n'); } return buf.toString(); } private  HexFormat(); }
HexFormat { public static String format(byte[] array, int len) { StringBuilder buf = new StringBuilder(); int lines = (len + 15) / 16; for (int i = 0; i < lines; i++) { int off = i * 16; buf.append(toHex(off, 4)); buf.append(" "); int bytes = Math.min(16, len - off); int j; for (j = 0; j < bytes; j++) { if (j == 8) buf.append(' '); buf.append(toHex(array[off + j] & 0xff, 2)); buf.append(' '); } for (; j < 16; j++) { if (j == 8) buf.append(' '); buf.append(" "); } buf.append(" "); for (j = 0; j < bytes; j++) { if (j == 8) buf.append(' '); int c = array[off + j] & 0xff; if (c >= 32 && c < 126) { buf.append((char) c); } else { buf.append('.'); } } if (i != (lines - 1)) buf.append('\n'); } return buf.toString(); } private  HexFormat(); static String format(byte[] array, int len); }
HexFormat { public static String format(byte[] array, int len) { StringBuilder buf = new StringBuilder(); int lines = (len + 15) / 16; for (int i = 0; i < lines; i++) { int off = i * 16; buf.append(toHex(off, 4)); buf.append(" "); int bytes = Math.min(16, len - off); int j; for (j = 0; j < bytes; j++) { if (j == 8) buf.append(' '); buf.append(toHex(array[off + j] & 0xff, 2)); buf.append(' '); } for (; j < 16; j++) { if (j == 8) buf.append(' '); buf.append(" "); } buf.append(" "); for (j = 0; j < bytes; j++) { if (j == 8) buf.append(' '); int c = array[off + j] & 0xff; if (c >= 32 && c < 126) { buf.append((char) c); } else { buf.append('.'); } } if (i != (lines - 1)) buf.append('\n'); } return buf.toString(); } private  HexFormat(); static String format(byte[] array, int len);  }