If you map a larger buffer over ByteBuffer , you can specify endianness using ByteOrder values. Old core libraries assume network order.
From ByteBuffer :
Binary access
This class defines methods for reading and writing the values of all other primitive types except boolean. Primitive values are translated into (or from) a sequence of bytes in accordance with the byte order of the current byte, which can be obtained and changed using order methods. Specific byte orders are represented by instances of the ByteOrder class. The initial byte buffer order is always BIG_ENDIAN.
and ByteOrder provides access to your own order for the platform on which you work.
Compare this to the old DataInput , which is not useful for interacting with local native services:
Reads four input bytes and returns an int value. Let ad be read from first to fourth bytes. Return value:
(((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff))
source share