Here you can find the source of hexDump(byte[] buffer)
public static String hexDump(byte[] buffer)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { static final String HEX_VALUES = "0123456789ABCDEF"; public static String hexDump(byte[] buffer) { StringBuilder buf = new StringBuilder(buffer.length << 1); for (byte b : buffer) addHexByte(buf, b);// w ww . j a v a2 s. c om return buf.toString(); } public static String hexDump(ByteBuffer buffer) { byte[] data = new byte[buffer.remaining()]; int pos = buffer.position(); buffer.get(data); buffer.position(pos); StringBuilder buf = new StringBuilder(buffer.remaining() + 22); for (byte b : data) addHexByte(buf, b); return buf.toString(); } private static void addHexByte(StringBuilder buf, byte b) { buf.append(HEX_VALUES.charAt((b & 0xF0) >> 4)).append(HEX_VALUES.charAt((b & 0x0F))); } }