X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2Futil%2FSeekable.java;h=964ebc2852da401d238e47679d62b3f371b9b029;hp=cacca0a3b9a700b28034c3522d76833b463f1820;hb=3e206c53f6ee3d09c3bb781526c0fe01bf8f6c75;hpb=6d6d9f59a2e6fe3b9e5b3563efcf0124bea4a672 diff --git a/src/org/ibex/nestedvm/util/Seekable.java b/src/org/ibex/nestedvm/util/Seekable.java index cacca0a..964ebc2 100644 --- a/src/org/ibex/nestedvm/util/Seekable.java +++ b/src/org/ibex/nestedvm/util/Seekable.java @@ -17,6 +17,10 @@ public abstract class Seekable { public void resize(long length) throws IOException { throw new IOException("resize not implemented for " + getClass()); } + /** If pos == 0 and size == 0 lock covers whole file. */ + public Lock lock(long pos, long size, boolean shared) throws IOException { + throw new IOException("lock not implemented for " + getClass()); + } public int read() throws IOException { byte[] buf = new byte[1]; @@ -71,12 +75,14 @@ public abstract class Seekable { } public static class File extends Seekable { + private final java.io.File file; 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,false); } public File(java.io.File file, boolean writable, boolean truncate) throws IOException { + this.file = file; String mode = writable ? "rw" : "r"; raf = truncate ? Platform.truncatedRandomAccessFile(file,mode) : new RandomAccessFile(file,mode); } @@ -88,6 +94,14 @@ public abstract class Seekable { public int length() throws IOException { return (int)raf.length(); } public void close() throws IOException { raf.close(); } public void resize(long length) throws IOException { raf.setLength(length); } + public boolean equals(Object o) { + return o != null && o instanceof File + && file.equals(((File)o).file); + } + public Lock lock(long pos, long size, boolean shared) + throws IOException { + return Platform.lockFile(this, raf, pos, size, shared); + } } public static class InputStream extends Seekable { @@ -135,4 +149,12 @@ public abstract class Seekable { public void close() throws IOException { is.close(); } } + public interface Lock { + public Seekable seekable(); + public boolean isShared(); + public boolean isValid(); + public void release() throws IOException; + public long position(); + public long size(); + } }