1. create a ByteBuffer from a byte array
byte[] bytes = new byte[10];
ByteBuffer buffer = ByteBuffer.wrap(bytes);
2. retrieve bytes between the position and limit
bytes = new byte[buffer.remaining()];
buffer.get(bytes, 0, bytes.length);
buffer.clear();
3. retrieve all bytes in the buffer
bytes = new byte[buffer.capacity()];
buffer.get(bytes, 0, bytes.length);