Listing 1: Java class to reverse byte order in primitive data types

class WindowsStream extends FilterInputStream 
{
   public WindowsStream(InputStream in)
   {super(in);}
 
   // byte (1 byte)
   public final byte readByte() throws IOException 
   {int a = in.read();
    return (byte)(a); 
   }

   //short(2 byte)
   public final short readShort() throws IOException 
   {InputStream in = this.in;
    int a1 = in.read(); 
    int a2 = in.read();
    return (short)((a2 << 8) + a1);
   }
 
   //int (4 byte)
   public final int readInt() throws IOException    
   {InputStream in=this.in;
    int a1=in.read(); 
    int a2=in.read();
    int a3=in.read();     
    int a4=in.read();
    return ((a4 << 24) + (a3 << 16) + (a2 << 8) + a1);
   } 

   //long (8 byte) 
   public final long readLong() throws IOException   
   {InputStream in = this.in;
    return (readInt() << 32L)+(readInt() & 0xFFFFFFFFL);
   }

   //float (4 byte)
   public final float readFloat() throws IOException  
   {return Float.intBitsToFloat(readInt());}

   //double(8 byte)
   public final double readDouble() throws IOException  
   {return Double.longBitsToDouble(readLong());} 
}
— End of Listing —