home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch13 / quake / ByteFlipInputStream.java < prev    next >
Text File  |  1997-01-17  |  2KB  |  49 lines

  1. // Class for dealing with byte ordering
  2.  
  3. // Written by Bernie Roehl, November 1996
  4.  
  5. package quake;
  6.  
  7. import java.io.*;
  8.  
  9. public class ByteFlipInputStream extends DataInputStream {
  10.  
  11.         protected byte[] buffer;
  12.  
  13.         protected DataInputStream in;
  14.  
  15.         public ByteFlipInputStream(DataInputStream input) {
  16.                 super(input);
  17.                 in = input;
  18.                 buffer = new byte[4];
  19.         }
  20.  
  21.         public final int readFlippedInt() throws IOException {
  22.                 buffer[3] = in.readByte();
  23.                 buffer[2] = in.readByte();
  24.                 buffer[1] = in.readByte();
  25.                 buffer[0] = in.readByte();
  26.                 DataInputStream d = new DataInputStream(new ByteArrayInputStream(buffer));
  27.                 return d.readInt();
  28.         }
  29.  
  30.         public final float readFlippedFloat() throws IOException {
  31.                 buffer[3] = in.readByte();
  32.                 buffer[2] = in.readByte();
  33.                 buffer[1] = in.readByte();
  34.                 buffer[0] = in.readByte();
  35.                 DataInputStream d = new DataInputStream(new ByteArrayInputStream(buffer));
  36.                 return d.readFloat();
  37.         }
  38.  
  39.         public final short readFlippedShort() throws IOException {
  40.                 buffer[1] = in.readByte();
  41.                 buffer[0] = in.readByte();
  42.                 DataInputStream d = new DataInputStream(new ByteArrayInputStream(buffer));
  43.                 return d.readShort();
  44.         }
  45.  
  46. }
  47.  
  48.  
  49.