Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: wordsmithing

In Java, data is stored in big-endian format (also called network order). That is, all data is represented sequentially starting from the most significant bit (MSB) to the least significant. JDK versions prior to JDK 1.4 required definition of custom methods that manage reversing byte order to maintain compatibility with little-endian systems. Correct handling of byte order related issues is critical when exchanging data in a networked environment that includes both big-endian and little-endian machines. Failure to handle byte ordering issues can cause unexpected program behavior.

...

Code Block
bgColor#ccccff
	 
DataInputStream dis = new DataInputStream(
  new FileInputStream("data"));

byte[] buffer = new byte[4];
int bytesRead = dis.read(buffer);  // Bytes are read into buffer
if (bytesRead != 4) {
    throw new IOException("Unexpected End of Stream");
}
int serialNumber = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).getInt();

...