Here you can find the source of toString(ByteBuffer buffer)
public static String toString(ByteBuffer buffer)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; import java.nio.charset.Charset; public class Main { public static String toString(Object... args) { StringBuilder s = new StringBuilder(); for (Object arg : args) { if (arg != null) { s.append(arg);/*from w w w . ja va 2s . c o m*/ } } return s.toString(); } public static String toString(ByteBuffer buffer) { /// Create a StringBuffer so that we can convert the bytes to a String StringBuffer response = new StringBuffer(); // Create a CharSet that knows how to encode and decode standard text (UTF-8) Charset charset = Charset.forName("UTF-8"); // Decode the buffer to a String using the CharSet and append it to our buffer response.append(charset.decode(buffer)); buffer.flip(); return response.toString(); } }