01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.geoserver.security;
06:
07: import java.io.File;
08: import java.io.FileInputStream;
09: import java.io.IOException;
10: import java.io.InputStream;
11: import java.util.Properties;
12:
13: /**
14: * A simple class to support reloadable property files. Watches last modified
15: * date on the specified file, and allows to read a Properties out of it.
16: *
17: * @author Administrator
18: *
19: */
20: public class PropertyFileWatcher {
21: File file;
22: private long lastModified = Long.MIN_VALUE;
23:
24: public PropertyFileWatcher(File file) {
25: this .file = file;
26: }
27:
28: public Properties getProperties() throws IOException {
29: Properties p = new Properties();
30:
31: if (file.exists()) {
32: InputStream is = null;
33:
34: try {
35: is = new FileInputStream(file);
36: p.load(is);
37: lastModified = file.lastModified();
38: } finally {
39: if (is != null) {
40: is.close();
41: }
42: }
43: }
44:
45: return p;
46: }
47:
48: public boolean isStale() {
49: return file.exists() && (file.lastModified() > lastModified);
50: }
51: }
|