4 package org.vamsas.client.simpleclient;
8 import org.vamsas.client.SimpleClient;
11 * @author jim Watches a particular file for its creation, deletion, or
14 public class FileWatcher {
16 private File subject = null;
18 private long lastStat[];
20 boolean exists = false;
23 * Make a watcher for a particular file. If the file doesn't exist, the
24 * watcher will watch for its creation (and indicate a change of state)
25 * For locked files, the removal of a lock constitutes a change of
26 * state if the file was modified.
30 private boolean checkLock() {
31 if (subject!=null && subject.exists()) {
32 Lock tl = new Lock(subject);
42 private long[] getStat(File subject) {
43 return new long[] { subject.lastModified(), subject.length() };
45 private boolean compStat(long[] stat, long[] newstat) {
46 if (stat[0]!=newstat[0] || stat[1]!=newstat[1])
50 private boolean check() {
51 if (subject != null) {
52 if (!subject.exists()) {
60 long[] newStat = getStat(subject); // subject.lastModified();
61 if (exists && ((compStat(lastStat, newStat) || checkLock()))) {
72 public FileWatcher(File subject) {
73 // TODO Auto-generated constructor stub
74 this.subject = subject;
78 public boolean hasChanged() {