copying bytes out of a ByteBuffer is easier than this.

All you need to do is

``` java
buffer.get(bytes);
```

And it'll fill the array.