Excerpt from the Java DataInputStream class, showing parts of the byte alignment and ordering code, which are extremely slow. The DataOutputStream implementation has a similar problem.

Power Java
High-Performance Java Software Development
James Schatzman and Roy Donehower
Listing 1. Excerpt from the Java DataInputStream class, showing parts of the byte alignment and ordering code, which are extremely slow. The DataOutputStream implementation has a similar problem.


public final double readDouble() throws IOException {
  return Double.longBitsToDouble(readLong());
}
public final long readLong() throws IOException {
   InputStream in = this.in;
   return ((long) (readInt()) < 32)="" +="" (readint()="" &="" 0xffffffffl);="" }="" public="" final="" int="" readint()="" throws="" ioexception="" {="" inputstream="" in="this.in;" int="" ch1="in.read();" int="" ch2="in.read();" int="" ch3="in.read();" int="" ch4="in.read();" if="" ((ch1="" |="" ch2="" |="" ch3="" |="" ch4)="">< 0)="" throw="" new="" eofexception();="" return="" ((ch1="">< 24)="" +="" (ch2="">< 16)="" +="" (ch3="">< 8)="" +="" (ch4="">< 0));="" }="">