Here you can find the source of dumpBytes(String headerStr, byte[] bytes)
Parameter | Description |
---|---|
headerStr | String that will be printed as header |
bytes | Bytes to be dumped as hex. |
public static void dumpBytes(String headerStr, byte[] bytes)
//package com.java2s; public class Main { final static char[] HEX_DIGIT = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /**/* w w w . j av a 2 s .c om*/ * Dumps (prints) the byte array. Debug method. * @param headerStr String that will be printed as header * @param bytes Bytes to be dumped as hex. */ public static void dumpBytes(String headerStr, byte[] bytes) { StringBuffer buf = new StringBuffer(bytes.length); buf.append("\n"); buf.append(headerStr).append("\n"); buf.append("bytes.length: ").append(bytes.length).append("\n"); int len = bytes.length; int i = 0; for (i = 0; i < len; i++) { buf.append(toHex(bytes[i]) + " "); if (0 == ((i + 1) % 8)) { buf.append("\n"); } } buf.append("\n"); System.out.println(buf.toString()); } /** * Converts one int to a hexadecimal ASCII string. * * @param val The integer * @return The hex string */ public static String toHex(int val) { int val1, val2; val1 = (val >> 4) & 0x0F; val2 = (val & 0x0F); return ("" + HEX_DIGIT[val1] + HEX_DIGIT[val2]); } }