// how to simulate a ByteBuffer.toArray ByteBuffer bb; ... byte[] contentsOnly = Arrays.copyOf( bb.array(), bb.position() );