Here you can find the source of readString(ByteBuffer buffer)
public static String readString(ByteBuffer buffer) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.ByteBuffer; public class Main { public static String readString(ByteBuffer buffer) throws IOException { byte[] data = new byte[256]; int i = 0, value = 0; for (i = 0; (i < data.length) && ((value = buffer.get()) > 0); ++i) { data[i] = (byte) value; }/* www . jav a2 s . co m*/ return new String(data, 0, i); } }