Here you can find the source of toString(ByteBuffer buffer)
public static String toString(ByteBuffer buffer) throws UnsupportedEncodingException
//package com.java2s; //License from project: Apache License import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; public class Main { public static String toString(ByteBuffer buffer) throws UnsupportedEncodingException { byte[] bytes = new byte[buffer.remaining()]; buffer.get(bytes);/*w w w . j a v a2s .c om*/ return new String(bytes, "utf-8"); } }