Here you can find the source of getNullTerminatedByte(ByteBuffer buffer)
public static byte[] getNullTerminatedByte(ByteBuffer buffer)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { private static final int NULL_TERMINATED_STRING_DELIMITER = 0; public static byte[] getNullTerminatedByte(ByteBuffer buffer) { int pos = buffer.position(); byte[] array = buffer.array(); int endPos = array.length - 1; for (int i = pos; i < array.length; i++) { if (NULL_TERMINATED_STRING_DELIMITER == array[i]) { endPos = i;/*from ww w. j a v a2 s. c o m*/ break; } } byte[] vBuf = new byte[endPos - pos]; buffer.get(vBuf); buffer.position(buffer.position() + 1); return vBuf; } }