3 import java.util.Vector;
13 private static final int BLOCK_SIZE = 512;
14 private static final int BLOCK_MASK = 511;
15 private static final int BLOCK_SHIFT = 9;
17 private InputStream src;
18 private RandomAccessFile ras;
22 private boolean foundEOS;
39 public int getFilePointer() throws IOException {
41 return (
int)ras.getFilePointer();
46 public int read() throws IOException {
50 int l1 = readUntil(l);
52 byte abyte0[] = (byte[])data.elementAt((
int)(pointer>>BLOCK_SHIFT));
53 return abyte0[(int)(pointer++ & BLOCK_MASK)] & 0xff;
58 public int read(byte[] bytes,
int off,
int len)
throws IOException {
60 throw new NullPointerException();
62 return ras.read(bytes, off, len);
63 if(off<0 || len<0 || off+len>bytes.length)
64 throw new IndexOutOfBoundsException();
67 int l = readUntil(pointer+len);
71 byte abyte1[] = (byte[])data.elementAt((
int)(pointer >> BLOCK_SHIFT));
72 int k = Math.min(len, BLOCK_SIZE - (
int)(pointer & BLOCK_MASK));
73 System.arraycopy(abyte1, (
int)(pointer & BLOCK_MASK), bytes, off, k);
79 public final void readFully(byte[] bytes)
throws IOException {
82 int len = bytes.length;
84 int l = read(bytes, read, len - read);
90 private int readUntil(
int l)
throws IOException {
95 int i = (int)(l >> BLOCK_SHIFT);
96 int j = length >> BLOCK_SHIFT;
97 for(
int k = j; k <= i; k++) {
98 byte abyte0[] =
new byte[BLOCK_SIZE];
99 data.addElement(abyte0);
103 int k1 = src.read(abyte0, j1, i1);
118 public void seek(
int loc)
throws IOException {
121 {ras.seek(loc);
return;}
128 public final int readInt() throws IOException {
133 if((i | j | k | l) < 0)
134 throw new EOFException();
136 return (i << 24) + (j << 16) + (k << 8) + l;
139 public final long readLong() throws IOException {
140 return ((
long)readInt() << 32) + ((long)readInt() & 0xffffffffL);
143 public final double readDouble() throws IOException {
144 return Double.longBitsToDouble(readLong());
147 public final short readShort() throws IOException {
151 throw new EOFException();
153 return (
short)((i << 8) + j);
156 public final float readFloat() throws IOException {
157 return Float.intBitsToFloat(readInt());
160 public void close() throws IOException {
165 data.removeAllElements();