Here you can find the source of extractNullTerminatedString(ByteBuffer bb)
public static String extractNullTerminatedString(ByteBuffer bb)
//package com.java2s; import java.nio.ByteBuffer; public class Main { public static String extractNullTerminatedString(ByteBuffer bb) { int start = bb.position(); byte[] buffer = new byte[bb.remaining()]; bb.get(buffer);//from w w w . ja v a2 s.co m String s = new String(buffer); int nullPos = s.indexOf(0); s = s.substring(0, nullPos); bb.position(start + s.length() + 1); return s; } }