Okay, I'm pretty new to Java, so I apologize if this question is silly.
I have a ByteBuffer object that contains a value that might be any number of bytes long, with the capacity of the buffer set to the length. What's the most efficient way to read the value in the buffer into the appropriate primitive type?
The code below is representative of the question I have.
long returnValue;
ByteBuffer bb = GetBuffer(blah);
if (bb.capacity() > 4)
{
returnValue = (long) <how to get value from the buffer here?>
}
else if (bb.capacity() > 2)
{
returnValue = (long) <and here...>
}
// etc...
Calling getLong() on the buffer results in an exception if the limit of the buffer is less than 8. I suppose I could construct a long from the individual bytes, but that seems unnecessarily complicated. Is there a better way?
Thanks much!