Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
	 
// read method
public static int readLittleEndianInteger(InputStream ips) throws IOException {
  int result;
  byte[] buffer = new byte[4];
  int check = ips.read(buffer);
  if (check != 4) throw new IOException("Unexpected End of Stream");
  result = (buffer[3] << 24) | (buffer[2] << 16) | (buffer[1] << 8)
 | buffer[0];
  return result;
}

// write method
public static void writeLittleEndianInteger(int i, OutputStream ops) throws IOException {
  int result;
  byte[] buffer = new byte[4];
  buffer[0] = (byte) i;
  buffer[1] = (byte) (i >> 8);
  buffer[2] = (byte) (i >> 16);
  buffer[3] = (byte) (i >> 24);
  ops.write(buffer);
}

...