Here you can find the source of getTerminatedArray(ByteBuffer buf)
public static byte[] getTerminatedArray(ByteBuffer buf)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static byte[] getTerminatedArray(ByteBuffer buf) { int start = buf.position(); while (buf.get() != 0) { }//from ww w . j a va 2 s . c om int end = buf.position(); byte[] bytes = new byte[end - start - 1]; //don't include terminator buf.position(start); buf.get(bytes); //put position after array buf.position(end); //skip terminator return bytes; } }