Java ByteBuffer Put getZeroTerminatedStringBytesArray( ByteBuffer inputBuffer)

Here you can find the source of getZeroTerminatedStringBytesArray( ByteBuffer inputBuffer)

Description

get Zero Terminated String Bytes Array

License

Open Source License

Declaration

public static byte[][] getZeroTerminatedStringBytesArray(
            ByteBuffer inputBuffer) 

Method Source Code

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

Related

  1. computeSize(ByteBuffer[] buffers)
  2. convert(Object lock, CharsetEncoder encoder, ByteBuffer bytes, CharBuffer chars, OutputStream out)
  3. deserializeString(ByteBuffer inputBuffer, Charset charset)
  4. extractString(ByteArrayOutputStream byteBuffer)
  5. flushOutputStreamWriter(OutputStream out, ByteBuffer bytes, CharsetEncoder encoder, Object lock)
  6. inputStream(ByteBuffer bytes)
  7. inputStreamToByteBuffer(InputStream input)
  8. inputStreamToByteBuffer(InputStream is)
  9. makeInputStream(final ByteBuffer buffer)