--- /dev/null
+// Copyright 2000-2006 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
+
+package org.ibex.io;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.zip.*;
+import org.ibex.util.*;
+
+public class PropertiesFile {
+
+ public static final int INTERVAL = 2000; /* ms */
+
+ private File f;
+ private long lastChecked = 0;
+ private long lastModified = 0;
+ private Properties props = null;
+
+ public PropertiesFile(File f) throws IOException {
+ this.f = f;
+ if (!f.exists()) throw new IOException("file " + f + " does not exist");
+ checkReload();
+ }
+
+ public String get(String key) {
+ checkReload();
+ return (String)props.get(key);
+ }
+
+ public void checkReload() {
+ long diff = System.currentTimeMillis() - lastChecked;
+ if (diff < INTERVAL) return;
+ lastChecked += diff;
+ try {
+ if (lastModified == f.lastModified()) return;
+ lastModified = f.lastModified();
+ Properties newProps = new Properties();
+ newProps.load(new FileInputStream(f));
+ props = newProps;
+ } catch (Exception e) { Log.warn(this, e); }
+ }
+
+}