X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fmips%2Futil%2FSeekableFile.java;fp=src%2Forg%2Fxwt%2Fmips%2Futil%2FSeekableFile.java;h=168d43a1c769ba74239f9a47355138517978bdd5;hp=0000000000000000000000000000000000000000;hb=3eb15f58ca0911489d7d9bdc0ac2c575d27a68d8;hpb=a6ee28ca37621098ed040e6d1c4ae103934c3e97 diff --git a/src/org/xwt/mips/util/SeekableFile.java b/src/org/xwt/mips/util/SeekableFile.java new file mode 100644 index 0000000..168d43a --- /dev/null +++ b/src/org/xwt/mips/util/SeekableFile.java @@ -0,0 +1,24 @@ +package org.xwt.mips.util; + +import java.io.*; + +public class SeekableFile implements SeekableData { + private final RandomAccessFile raf; + + public SeekableFile(String fileName) throws IOException { this(fileName,false); } + public SeekableFile(String fileName, boolean writable) throws IOException { this(new File(fileName),writable); } + + public SeekableFile(File file, boolean writable) throws IOException { + raf = new RandomAccessFile(file,writable ? "rw" : "r"); + } + + // NOTE: RandomAccessFile.setLength() is a Java2 function + public void setLength(int n) throws IOException { raf.setLength(n); } + + public int read(byte[] buf, int offset, int length) throws IOException { return raf.read(buf,offset,length); } + public int write(byte[] buf, int offset, int length) throws IOException { raf.write(buf,offset,length); return length; } + public void seek(int pos) throws IOException{ raf.seek(pos); } + public int pos() throws IOException { return (int) raf.getFilePointer(); } + public int length() throws IOException { return (int)raf.length(); } + public void close() throws IOException { raf.close(); } +}