Java ByteBuffer Get getZeroTerminatedStringBytes(ByteBuffer dataBuffer)

Here you can find the source of getZeroTerminatedStringBytes(ByteBuffer dataBuffer)

Description

get Zero Terminated String Bytes

License

Open Source License

Declaration

public static byte[] getZeroTerminatedStringBytes(ByteBuffer dataBuffer) 

Method Source Code

//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();
    }
}

Related

  1. getUTF8FromByteBuffer(ByteBuffer bb)
  2. getUUID(ByteBuffer bytes)
  3. getVariance(ByteBuffer simulationResults)
  4. getVInt(ByteBuffer bf, int index)
  5. getWithShortLength(ByteBuffer bb)
  6. getZipEocdCentralDirectorySizeBytes(ByteBuffer zipEndOfCentralDirectory)
  7. insertByteArray(byte[] source, ByteBuffer target)
  8. transfer(ByteBuffer src, FileChannel target, long position, long count)
  9. transferUntilTargetPos(ByteBuffer src, ByteBuffer trg, int trgPos)