r2853 - isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util
Author: chatellier Date: 2009-12-21 09:50:24 +0000 (Mon, 21 Dec 2009) New Revision: 2853 Removed: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileChangeListener.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileEvent.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileMonitor.java Log: Remove unused classes. Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileChangeListener.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileChangeListener.java 2009-12-21 08:49:22 UTC (rev 2852) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileChangeListener.java 2009-12-21 09:50:24 UTC (rev 2853) @@ -1,16 +0,0 @@ -package fr.ifremer.isisfish.util; - -/** - * For listening modification on a file - * - * @author chemit - */ -public interface FileChangeListener { - - /** - * Invoked when a file changes. - * - * @param event event. - */ - public void fileChanged(FileEvent event); -} Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileEvent.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileEvent.java 2009-12-21 08:49:22 UTC (rev 2852) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileEvent.java 2009-12-21 09:50:24 UTC (rev 2853) @@ -1,33 +0,0 @@ -package fr.ifremer.isisfish.util; - -import java.util.EventObject; - -public class FileEvent extends EventObject { - - /** file location */ - protected String filename; - - /** file lastModified value */ - protected long lastModified; - - /** file length value */ - public long length; - - private static final long serialVersionUID = -6758072587195502206L; - - public FileEvent(Object source, String filename, long lastModified, long length) { - super(source); - this.filename = filename; - this.lastModified = lastModified; - this.length = length; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(super.toString()); - sb.append("\n( name ").append(filename).append(")"); - sb.append("\n( lastModified ").append(lastModified).append(")"); - sb.append("\n( length ").append(length).append(")"); - return sb.toString(); - } -} Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileMonitor.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileMonitor.java 2009-12-21 08:49:22 UTC (rev 2852) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/FileMonitor.java 2009-12-21 09:50:24 UTC (rev 2853) @@ -1,100 +0,0 @@ -package fr.ifremer.isisfish.util; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.Hashtable; -import java.util.Timer; -import java.util.TimerTask; - -/** - * This is a monitor for file (listen for modification on files) - * - * @author chemit - * @see FileChangeListener - * @see FileEvent - */ -public class FileMonitor { - - private static final FileMonitor instance = new FileMonitor(); - - private Timer timer; - private Hashtable<String, FileMonitorTask> timerEntries; - - public static FileMonitor getInstance() { - return instance; - } - - protected FileMonitor() { - // Create timer, run timer thread as daemon. - timer = new Timer(true); - timerEntries = new Hashtable<String, FileMonitorTask>(); - } - - /** - * Add a monitored file with a FileChangeListener. - * - * @param listener listener to notify when the file changed. - * @param fileName name of the file to monitor. - * @param period polling period in milliseconds. - * @throws FileNotFoundException if file not found - */ - public void addFileChangeListener(FileChangeListener listener, String fileName, long period) throws FileNotFoundException { - removeFileChangeListener(listener, fileName); - FileMonitorTask task = new FileMonitorTask(listener, fileName); - timerEntries.put(fileName + listener.hashCode(), task); - timer.schedule(task, period, period); - } - - /** - * Remove the listener from the notification list. - * - * @param listener the listener to be removed. - * @param fileName the filename listened - */ - public void removeFileChangeListener(FileChangeListener listener, String fileName) { - FileMonitorTask task = timerEntries.remove(fileName + listener.hashCode()); - if (task != null) { - task.cancel(); - } - } - - protected void fireFileChangeEvent(FileChangeListener listener, - String fileName, long lastModified, - long length) { - listener.fileChanged(new FileEvent(listener, fileName, lastModified, length)); - } - - class FileMonitorTask extends TimerTask { - FileChangeListener listener; - String fileName; - File monitoredFile; - long lastModified; - long length; - - public FileMonitorTask(FileChangeListener listener, String fileName) - throws FileNotFoundException { - this.listener = listener; - this.fileName = fileName; - this.lastModified = 0; - this.length = 0; - - monitoredFile = new File(fileName); - if (!monitoredFile.exists()) { - throw new FileNotFoundException("File Not Found: " + fileName); - } - - this.lastModified = monitoredFile.lastModified(); - //this.length = monitoredFile.length(); - } - - public void run() { - long lastModified = monitoredFile.lastModified(); - long length = monitoredFile.length(); - if (lastModified != this.lastModified || length != this.length) { - this.lastModified = lastModified; - this.length = length; - fireFileChangeEvent(this.listener, this.fileName, this.lastModified, this.length); - } - } - } -}
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org