Here you can find the source of print(ByteBuffer byteBuffer)
public static String print(ByteBuffer byteBuffer)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static String print(String txt) { StringBuilder builder = new StringBuilder(); builder.append("byte[] a= DatatypeConverter.parseHexBinary(\""); for (byte b : txt.getBytes()) { builder.append(getTwoDigitHex(b)); }//from ww w .j av a2 s .co m builder.append("\");"); return builder.toString(); } public static String print(ByteBuffer byteBuffer) { String text = new String(byteBuffer.array()); return print(text); } private static String getTwoDigitHex(byte b) { String hex = String.format("%02X ", b).substring(0, 2); return hex; } }