Here you can find the source of toString(ByteBuffer value, String charsetName)
static public String toString(ByteBuffer value, String charsetName)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { /**//from ww w . ja v a 2 s . c o m * convert a ByteBuffer to a String * ByteBuffer is reset to its original state. */ static public String toString(ByteBuffer value, String charsetName) { String result = null; try { result = new String(toBytes(value), charsetName); } catch (Exception e) { } return result; } static public String toString(int value, int radix, int minChars) { String result = Integer.toString(value, radix); int leadZeroes = minChars - result.length(); if (leadZeroes > 0) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < leadZeroes; i++) { buf.append("0"); } buf.append(result); result = buf.toString(); } return result; } /** * Convert a ByteBuffer to a byte[] * ByteBuffer is reset to its original state. */ static public byte[] toBytes(ByteBuffer value) { byte[] result = null; if (value != null && value.remaining() > 0) { result = new byte[value.remaining()]; value.mark(); value.get(result); value.reset(); } return result; } }