Android ByteBuffer Get extractNullTerminatedString(ByteBuffer bb)

Here you can find the source of extractNullTerminatedString(ByteBuffer bb)

Description

extract Null Terminated String

Declaration

public static String extractNullTerminatedString(ByteBuffer bb) 

Method Source Code

//package com.java2s;
import java.nio.ByteBuffer;

public class Main {
    public static String extractNullTerminatedString(ByteBuffer bb) {
        int start = bb.position();

        byte[] buffer = new byte[bb.remaining()];

        bb.get(buffer);//from  w  w w .  ja  v  a2 s.co  m

        String s = new String(buffer);
        int nullPos = s.indexOf(0);

        s = s.substring(0, nullPos);

        bb.position(start + s.length() + 1);

        return s;
    }
}

Related

  1. getUnsignedByte(final ByteBuffer pByteBuffer)
  2. getUnsignedByte(final ByteBuffer pByteBuffer, final int pPosition)
  3. getUnsignedInt(final ByteBuffer pByteBuffer)
  4. getUnsignedInt(final ByteBuffer pByteBuffer, final int pPosition)
  5. allocateMore(ByteBuffer output)
  6. removeFirstBytes(ByteBuffer buffer, int num)
  7. shorts(ByteBuffer buffer)
  8. getObject(ByteBuffer byteBuffer)