1 package com.quadcap.io; 2 3 40 41 import java.io.InputStream ; 42 import java.io.IOException ; 43 import java.io.RandomAccessFile ; 44 45 import com.quadcap.util.Debug; 46 47 53 public class RandomAccessFileInputStream extends InputStream { 54 long mark = -1; 55 RandomAccessFile ra; 56 57 63 public RandomAccessFileInputStream(RandomAccessFile ra) { 64 this.ra = ra; 65 } 66 67 72 public int read() throws IOException { 73 return ra.read(); 75 } 76 77 82 public int read(byte[] buf, int offset, int count) throws IOException { 83 return ra.read(buf, offset, count); 85 } 86 87 92 public int read(byte[] buf) throws IOException { 93 return ra.read(buf); 96 } 97 98 101 public int available() throws IOException { 102 return (int)(ra.length() - ra.getFilePointer()); 103 } 104 105 108 public void close() throws IOException { 109 ra.close(); 110 } 111 112 115 public long skip(long n) throws IOException { 116 ra.seek(ra.getFilePointer() + n); 117 return n; 118 } 119 120 123 public void mark(int readLimit) { 124 try { 125 this.mark = ra.getFilePointer(); 126 } catch (IOException e) { 127 Debug.print(e); 128 throw new RuntimeException (e.toString()); 129 } 130 } 131 132 135 public void reset() throws IOException { 136 if (mark < 0) throw new IOException ("no mark"); 137 ra.seek(mark); 138 } 139 140 143 public boolean markSupported() { 144 return true; 145 } 146 } 147 | Popular Tags |