Basically, I would like to know if there is a difference in casting performance or is it better to use a larger ByteBuffer.
Casting is “cheap” especially compared to distributing new ByteBufferand calling several methods.
I'm not quite sure what you are trying to do, but maybe a simple transition-right will do the trick? For example, this piece of code:
long l = rs.getLong(index);
InetAddress.getByAddress(new byte[] { (byte) ((l & 0xFF000000) >> 24),
(byte) ((l & 0x00FF0000) >> 16),
(byte) ((l & 0x0000FF00) >> 8),
(byte) ((l & 0x000000FF) >> 0)});
aioobe source
share