/** * Read a 32-bit signed int, in little-endian binary format. * * @param dis stream to read from. * * @return binary value. */ static int readIntLittleEndian( DataInputStream dis ) throws IOException { // get 4 unsigned byte components, and accumulate into an int. int accum = 0; for ( int shiftBy = 0; shiftBy < 32; shiftBy += 8 ) { accum |= ( dis.readByte() & 0xff ) << shiftBy; } return accum; // rem in JDK 1.5+ you can say: // return Integer.reverseBytes( i ); }