Here you can find the source of byteBufferToString(ByteBuffer stringBuf)
private static String byteBufferToString(ByteBuffer stringBuf)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { private static String byteBufferToString(ByteBuffer stringBuf) { /* The (- 1) is to remove the \0 character */ byte[] bytes = new byte[stringBuf.remaining() - 1]; stringBuf.get(bytes);/*from ww w . jav a2 s. c om*/ return new String(bytes); } }