/** * */ package org.vamsas.client.simpleclient; import java.io.File; /** * @author jim * Watches a particular file for its creation, deletion, or modification. */ public class FileWatcher { private File subject=null; private long lastStat; boolean exists=false; /** * Make a watcher for a particular file. * If the file doesn't exist, the watcher will watch * for its creation (and indicate a change of state) * @param subject */ private boolean check() { if (subject!=null) { if (!subject.exists()) { if (exists) { exists=false; return true; } return false; } else { long newStat=subject.lastModified(); if (exists && lastStat==newStat) { return false; } lastStat=newStat; exists=true; return true; } } return false; } public FileWatcher(File subject) { // TODO Auto-generated constructor stub this.subject = subject; check(); } public boolean hasChanged() { return check(); } }