Java examples for java.nio:ByteBuffer String
extract Null Terminated String from ByteBuffer
//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);//www .jav a 2 s . c o m String s = new String(buffer); int nullPos = s.indexOf(0); s = s.substring(0, nullPos); bb.position(start + s.length() + 1); return s; } }