home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch13
/
quake
/
ByteFlipInputStream.java
< prev
next >
Wrap
Text File
|
1997-01-17
|
2KB
|
49 lines
// Class for dealing with byte ordering
// Written by Bernie Roehl, November 1996
package quake;
import java.io.*;
public class ByteFlipInputStream extends DataInputStream {
protected byte[] buffer;
protected DataInputStream in;
public ByteFlipInputStream(DataInputStream input) {
super(input);
in = input;
buffer = new byte[4];
}
public final int readFlippedInt() throws IOException {
buffer[3] = in.readByte();
buffer[2] = in.readByte();
buffer[1] = in.readByte();
buffer[0] = in.readByte();
DataInputStream d = new DataInputStream(new ByteArrayInputStream(buffer));
return d.readInt();
}
public final float readFlippedFloat() throws IOException {
buffer[3] = in.readByte();
buffer[2] = in.readByte();
buffer[1] = in.readByte();
buffer[0] = in.readByte();
DataInputStream d = new DataInputStream(new ByteArrayInputStream(buffer));
return d.readFloat();
}
public final short readFlippedShort() throws IOException {
buffer[1] = in.readByte();
buffer[0] = in.readByte();
DataInputStream d = new DataInputStream(new ByteArrayInputStream(buffer));
return d.readShort();
}
}