1 package org.xwt.mips.util;
5 public class SeekableFile implements SeekableData {
6 private final RandomAccessFile raf;
8 public SeekableFile(String fileName) throws IOException { this(fileName,false); }
9 public SeekableFile(String fileName, boolean writable) throws IOException { this(new File(fileName),writable); }
11 public SeekableFile(File file, boolean writable) throws IOException {
12 raf = new RandomAccessFile(file,writable ? "rw" : "r");
15 // NOTE: RandomAccessFile.setLength() is a Java2 function
16 public void setLength(int n) throws IOException { raf.setLength(n); }
18 public int read(byte[] buf, int offset, int length) throws IOException { return raf.read(buf,offset,length); }
19 public int write(byte[] buf, int offset, int length) throws IOException { raf.write(buf,offset,length); return length; }
20 public void seek(int pos) throws IOException{ raf.seek(pos); }
21 public int pos() throws IOException { return (int) raf.getFilePointer(); }
22 public int length() throws IOException { return (int)raf.length(); }
23 public void close() throws IOException { raf.close(); }