Here you can find the source of toHexString(ByteBuffer buffer)
public static String toHexString(ByteBuffer buffer)
//package com.java2s; import java.nio.ByteBuffer; public class Main { private static final char[] HEX_CODE = "0123456789abcdef".toCharArray(); public static String toHexString(ByteBuffer buffer) { final StringBuilder r = new StringBuilder(buffer.remaining() * 2); while (buffer.hasRemaining()) { final byte b = buffer.get(); r.append(HEX_CODE[(b >> 4) & 0xF]); r.append(HEX_CODE[(b & 0xF)]); }/*w ww .j av a2s . c o m*/ return r.toString(); } }