X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2Futil%2FSeekable.java;fp=src%2Forg%2Fibex%2Fnestedvm%2Futil%2FSeekable.java;h=51c7a3959d8782428f055e1064ae977dd510386a;hp=cf8cca776eab2390421b127f679e47235bea5d78;hb=103c9465744d35d6ade7c0520a5faa2c6375e7b2;hpb=6cf1ec7685f99f9a2f46e9ad6d29ae52d3125579 diff --git a/src/org/ibex/nestedvm/util/Seekable.java b/src/org/ibex/nestedvm/util/Seekable.java index cf8cca7..51c7a39 100644 --- a/src/org/ibex/nestedvm/util/Seekable.java +++ b/src/org/ibex/nestedvm/util/Seekable.java @@ -66,15 +66,13 @@ public abstract class Seekable { private final RandomAccessFile raf; public File(String fileName) throws IOException { this(fileName,false); } - public File(String fileName, boolean writable) throws IOException { this(new java.io.File(fileName),writable); } + public File(String fileName, boolean writable) throws IOException { this(new java.io.File(fileName),writable,false); } - public File(java.io.File file, boolean writable) throws IOException { - raf = new RandomAccessFile(file,writable ? "rw" : "r"); + public File(java.io.File file, boolean writable, boolean truncate) throws IOException { + String mode = writable ? "rw" : "r"; + raf = truncate ? Platform.truncatedRandomAccessFile(file,mode) : new RandomAccessFile(file,mode); } - // 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); }