I'm not sure why the following example gives buffer overflow exception. Hope someone can explain why, and how i can do it correctly.
It's as simple as this:
ByteBuffer bf = ByteBuffer.allocate(4);
bf.order(ByteOrder.BIG_ENDIAN);
bf.putInt(8);
bf.putInt(7); // Throws exception
The goal: [0,0,8,7]
Thanks in advance!
An int is 4 bytes long so you should multiply 4 to the number of int you need to store in your ByteBuffer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With