Here you can find the source of getZeroTerminatedStringBytes(ByteBuffer dataBuffer)
public static byte[] getZeroTerminatedStringBytes(ByteBuffer dataBuffer)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; public class Main { public static byte[] getZeroTerminatedStringBytes(ByteBuffer dataBuffer) { ByteArrayOutputStream bos = new ByteArrayOutputStream( dataBuffer.remaining()); while (dataBuffer.remaining() > 0) { byte thisByte = dataBuffer.get(); if (thisByte == 0) { break; }//from w ww. j av a 2 s . c om bos.write(thisByte); } return bos.toByteArray(); } }