• Post Reply Bookmark Topic Watch Topic
  • New Topic

int to byte[] gives BufferOverflowException  RSS feed

 
Raghava Mutharaju
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am trying to convert int to a byte array with the code below


I am getting a BufferOverflowException, if I allocate one byte for 2. Isn't it supposed to take only 1 byte? Unless I allocate 4 bytes, it gives the exception (even if I allocate 2 or 3 bytes). This might be something very simple and I might have asked a pretty silly question. But, what am I missing here?
 
Ralph Cook
Ranch Hand
Posts: 479
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the javadoc for ByteBuffer.putInt(int value):

Writes four bytes containing the given int value, in the current byte order, into this buffer at the current position, and then increments the position by four.

rc
 
Raghava Mutharaju
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ok, I got it now. Thank you for pointing it out

Regards,
Raghava.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!