Here you can find the source of getString(ByteBuffer buffer, int size)
public static String getString(ByteBuffer buffer, int size)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; import java.nio.charset.Charset; public class Main { public static String getString(ByteBuffer buffer, int size) { assert (0 < size); assert (buffer.capacity() - buffer.position() >= size); ByteBuffer buf = ByteBuffer.allocate(size); buffer.get(buf.array(), 0, size); try {//from w ww . j a v a 2 s . c o m return Charset.defaultCharset().newDecoder().decode(buf).toString().trim(); } catch (Exception e) { e.printStackTrace(); assert (false); return ""; } } }