Here you can find the source of bytesToHex(ByteBuffer bytes)
public static String bytesToHex(ByteBuffer bytes)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); public static String bytesToHex(ByteBuffer bytes) { char[] hexChars = new char[bytes.limit() * 2]; for (int j = 0; j < bytes.limit(); j++) { int v = bytes.get() & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; }/*from www.java 2 s . c o m*/ return new String(hexChars); } }