Android Utililty Methods ByteBuffer Get

List of utility methods to do ByteBuffer Get

Description

The list of methods to do ByteBuffer Get are organized into topic(s).

Method

shortgetUnsignedByte(final ByteBuffer pByteBuffer)
get Unsigned Byte
return (short) (pByteBuffer.get() & 0xFF);
shortgetUnsignedByte(final ByteBuffer pByteBuffer, final int pPosition)
get Unsigned Byte
return (short) (pByteBuffer.get(pPosition) & (short) 0xFF);
longgetUnsignedInt(final ByteBuffer pByteBuffer)
get Unsigned Int
return pByteBuffer.getInt() & 0xFFFFFFFFL;
longgetUnsignedInt(final ByteBuffer pByteBuffer, final int pPosition)
get Unsigned Int
return pByteBuffer.getInt(pPosition) & 0xFFFFFFFFL;
StringextractNullTerminatedString(ByteBuffer bb)
extract Null Terminated String
int start = bb.position();
byte[] buffer = new byte[bb.remaining()];
bb.get(buffer);
String s = new String(buffer);
int nullPos = s.indexOf(0);
s = s.substring(0, nullPos);
bb.position(start + s.length() + 1);
return s;
...
ByteBufferallocateMore(ByteBuffer output)
allocate More
if (output.capacity() == 0) {
    return ByteBuffer.allocate(1);
ByteBuffer result = ByteBuffer.allocate(output.capacity() * 2);
output.flip();
result.put(output);
return result;
ByteBufferremoveFirstBytes(ByteBuffer buffer, int num)
remove First Bytes
buffer.position(buffer.limit() - num);
byte[] tmp = new byte[buffer.remaining()];
buffer.get(tmp);
ByteBuffer res = ByteBuffer.wrap(tmp);
res.rewind();
return res;
short[]shorts(ByteBuffer buffer)
shorts
ShortBuffer samples = buffer.asShortBuffer();
short[] shorts = new short[samples.limit()];
for (int i = 0; i < samples.limit(); i++)
    shorts[i] = samples.get(i);
return shorts;
ObjectgetObject(ByteBuffer byteBuffer)
get Object
InputStream input = new ByteArrayInputStream(byteBuffer.array());
ObjectInputStream oi = new ObjectInputStream(input);
Object obj = oi.readObject();
input.close();
oi.close();
byteBuffer.clear();
return obj;
voidskip(ByteBuffer buffer, int length)
Increment position in buffer.
buffer.position(buffer.position() + length);