/** * Read a 16-bit signed long, in little-endian binary format. * * @param dis stream to read from. * * @return binary value. */ static short readLongLittleEndian( DataInputStream dis ) throws IOException // 8 bytes, get each byte unsigned, and accumulate them onto the long long accum = 0; for ( int shiftBy=0; shiftBy<64; shiftBy+=8 ) { // must cast to long or the shift would be done modulo 32 accum |= (long)( dis.readByte() & 0xff ) << shiftBy; } return accum; // rem in JDK 1.5+ you can say: // return Long.reverseBytes( l ); }