- Fully reload properties whenever one of its ingredients is changed

(main file or additional props from zip file).
- Remove deprecated constructor
This commit is contained in:
hns 2004-02-10 14:43:55 +00:00
parent 0def62ee5a
commit a556621554

View file

@ -45,26 +45,6 @@ public final class SystemProperties extends Properties {
this(null, null); this(null, null);
} }
/**
* Construct a properties object and read it from an input stream.
*/
public SystemProperties(InputStream in) {
this(null, null);
try {
load(in);
} catch (Exception x) {
System.err.println("Error reading properties from file " + file + ": " + x);
} finally {
try {
in.close();
} catch (Exception ignore) {
}
}
lastread = System.currentTimeMillis();
}
/** /**
* Construct a properties object from a properties file. * Construct a properties object from a properties file.
*/ */
@ -124,18 +104,24 @@ public final class SystemProperties extends Properties {
*/ */
private void checkFile() { private void checkFile() {
if ((file != null) && (file.lastModified() > lastread)) { if ((file != null) && (file.lastModified() > lastread)) {
readFile(); reload();
} }
lastcheck = System.currentTimeMillis(); lastcheck = System.currentTimeMillis();
} }
/** /**
* Private method to read the underlying properties file. Assumes that the * Reload properties. This clears out the existing entries,
* file exists and is readable. * loads the main properties file and then adds any additional
* properties there may be (usually from zip files). This is used
* internally by addProps() and removeProps().
*/ */
private synchronized void readFile() { private synchronized void reload() {
// IServer.getLogger().log ("Reading properties from file "+file); // clear out old entries
clear();
// read from the primary file
if (file != null) {
FileInputStream bpin = null; FileInputStream bpin = null;
try { try {
@ -147,21 +133,12 @@ public final class SystemProperties extends Properties {
try { try {
bpin.close(); bpin.close();
} catch (Exception ignore) { } catch (Exception ignore) {
// ignored
} }
} }
} }
/** // read additional properties from zip files, if available
*
*
* @param in ...
*
* @throws IOException ...
*/
public synchronized void load(InputStream in) throws IOException {
clear();
super.load(in);
if (additionalProps != null) { if (additionalProps != null) {
for (Iterator i = additionalProps.values().iterator(); i.hasNext();) for (Iterator i = additionalProps.values().iterator(); i.hasNext();)
putAll((Properties) i.next()); putAll((Properties) i.next());
@ -176,16 +153,16 @@ public final class SystemProperties extends Properties {
*/ */
public synchronized void addProps(String key, InputStream in) public synchronized void addProps(String key, InputStream in)
throws IOException { throws IOException {
Properties p = new SystemProperties(); Properties newProps = new SystemProperties();
newProps.load(in);
p.load(in);
if (additionalProps == null) { if (additionalProps == null) {
additionalProps = new HashMap(); additionalProps = new HashMap();
} }
additionalProps.put(key, newProps);
additionalProps.put(key, p); // fully reload properties and mark as updated
putAll(p); reload();
lastadd = System.currentTimeMillis(); lastadd = System.currentTimeMillis();
} }
@ -199,6 +176,8 @@ public final class SystemProperties extends Properties {
Object p = additionalProps.remove(key); Object p = additionalProps.remove(key);
if (p != null) { if (p != null) {
// fully reload properties and mark as updated
reload();
lastadd = System.currentTimeMillis(); lastadd = System.currentTimeMillis();
} }
} }