import java.io.DataInputStream; import java.io.EOFException; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Stack; public class HexInputStream { private volatile InputStream dis; private volatile long currPos; public long getPosition(){ return this.currPos; } public void setPosition(long newPos) throws IOException{ this.skip(newPos - currPos); } public void goTo(long pos) throws IOException{ this.setPosition(pos); } private Stack positionStack; public HexInputStream(InputStream baseInputStream) { this.dis = baseInputStream; this.currPos = 0; this.positionStack = new Stack(); } public HexInputStream(String filename) throws FileNotFoundException { this.dis = new DataInputStream(new FileInputStream(new File(filename))); this.currPos = 0; this.positionStack = new Stack(); } public int available() throws IOException{ return dis.available(); } /** Read the next byte from a file. If the EOF has been reached, -1 is returned */ public int read() throws IOException{ int b = dis.read(); if(b != -1) currPos++; return b; } /** Read an array of bytes from this stream */ public int[] readBytes(int length) throws IOException{ int[] data = new int[length]; for(int i=0; i