Name: jl125535 Date: 08/01/2003
A DESCRIPTION OF THE REQUEST :
Please add public static int fields in all primitive wrapper classes that contain the size of the type in bytes.
This is trivial, but it gets annoying once you add your own static fields to classes a few different times.
JUSTIFICATION :
Currently, whenever dealing with ByteBuffers and you need to retrieve primitive types using their absolute position within the Buffer, you always need to have your own fields in your class with the size of each primitive type in bytes. While this is not a terrible hardship, it would be simpler, much more elegant, and logical for each primitive wrapper to have constant fields available so that it is immediately apparent what you're up to.
EXPECTED VERSUS ACTUAL BEHAVIOR :
When retrieving data from some buffer, for instance one you have received from a DatagramChannel, and you know the data is stored like this:
a short with the message type
a long with the timestamp
two ints with data
and if you want to retrieve your data using absolute positioning, it seems reasonable to be able retreive it like this:
short type = buffer.getShort(0 * Short.SIZE);
long timeStampe = buffer.getShort(Short.SIZE);
int firstData = buffer.getShort(Short.SIZE + Long.SIZE);
int secondData = buffer.getShort(Short.SIZE + Long.SIZE + Integer.SIZE);
You define your own static fields.
CUSTOMER SUBMITTED WORKAROUND :
Define your own static variables, or use relative reading (you can store the initial position and then put the 'cursor' back there when you're done).
(Incident Review ID: 182352)
======================================================================