- public Watcher watcher() { return this; }
- public abstract void changed(Watched w);
- public synchronized void scan() throws IOException { super.scan(); }
+
+ public abstract void changed(File f) throws IOException;
+
+ private Vec watched = new Vec();
+
+ public void watch(File f) { watched.addElement(new Watched(f.getAbsolutePath())); }
+ public void watch(String s) { watch(new File(getAbsolutePath() + File.separatorChar + s)); }
+
+ public void scan() throws IOException {
+ for(int i=watched.size()-1; i>=0; i--)
+ ((Watched)(watched.elementAt(i))).scan();
+ }
+
+ private class Watched extends File {
+ long lastModifiedAtLastScan = -1;
+ public Watched(String s) { super(s); }
+ public void scan() throws IOException {
+ // FIXME
+ //if (!exists()) { Watcher.this.changed(this); Watcher.this.watched.remove(this); return; }
+ if (lastModifiedAtLastScan != lastModified()) { Watcher.this.changed(this); lastModifiedAtLastScan = lastModified(); }
+ }
+ }