Here you can find the source of getZeroTerminatedStringBytesArray( ByteBuffer inputBuffer)
public static byte[][] getZeroTerminatedStringBytesArray( ByteBuffer inputBuffer)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; import java.util.ArrayList; public class Main { public static byte[][] getZeroTerminatedStringBytesArray( ByteBuffer inputBuffer) { ArrayList<byte[]> array = new ArrayList<>(); while (inputBuffer.remaining() > 0) { array.add(getZeroTerminatedStringBytes(inputBuffer)); }/*from w w w. ja va2s .c om*/ return array.toArray(new byte[array.size()][]); } public static byte[] getZeroTerminatedStringBytes(ByteBuffer dataBuffer) { ByteArrayOutputStream bos = new ByteArrayOutputStream( dataBuffer.remaining()); while (dataBuffer.remaining() > 0) { byte thisByte = dataBuffer.get(); if (thisByte == 0) { break; } bos.write(thisByte); } return bos.toByteArray(); } }