Here you can find the source of bufferToString(ByteBuffer buff)
public static String bufferToString(ByteBuffer buff)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; public class Main { public static String bufferToString(ByteBuffer buff) { Charset charset = Charset.forName("UTF-8"); CharsetDecoder decoder = charset.newDecoder(); String message = ""; try {//w w w . ja v a2 s.com message = decoder.decode(buff).toString(); } catch (Exception e) { message = e.getMessage(); } return message; } }