The topic is rather simple, but I might have confused myself a bit here. Network byte order is Big-Endian. Java by default uses Big-endian as well (as in the case of class files). My windows machine uses Intel processors, which are Little-Endian and windows itself also uses Little-Endian. So, if I uses a java.nio.ByteBuffer.allocateDirect(), then the default Endianness is Little-Endian (because of the OS and/or the processor), however, if I want to send this data on network, on reading data from ByteBuffer, do I need to use ByteBuffer.order(ByteOrder.BIG_ENDIAN)? Additionally, Do i have to do the reverse while reading the data from a Channel to a ByteBuffer? I almost ignored it when using java.io package
Another part of the question is also related to working on the machine itself.
- Should I always be aware of the Endianness of my host machine? So, whatever local data storage format is used, its fine within this machine's environment, however, convert the data to BIG_ENDIAN when sending to network.
- In terms of Endianness, for default file formats, say on windows, its always Little-Endian. However, now using the same file on a MAC or a Linux with Big-Endian, should I save it with a Byte-order-Marking (BOM)?