overrided load() function to load properties into a fresh map,
added add() function to load a file without discarding old entries.
This commit is contained in:
parent
f3371c79f1
commit
93e6af7799
1 changed files with 25 additions and 5 deletions
|
@ -79,7 +79,7 @@ public final class SystemProperties extends Properties {
|
||||||
*/
|
*/
|
||||||
public long lastModified () {
|
public long lastModified () {
|
||||||
if (file == null || !file.exists ())
|
if (file == null || !file.exists ())
|
||||||
return 0;
|
return lastread;
|
||||||
return file.lastModified ();
|
return file.lastModified ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,20 +98,40 @@ public final class SystemProperties extends Properties {
|
||||||
*/
|
*/
|
||||||
private synchronized void readFile () {
|
private synchronized void readFile () {
|
||||||
// IServer.getLogger().log ("Reading properties from file "+file);
|
// IServer.getLogger().log ("Reading properties from file "+file);
|
||||||
newProps = defaultProps == null ?
|
FileInputStream bpin = null;
|
||||||
new Properties () : new Properties (defaultProps);
|
|
||||||
try {
|
try {
|
||||||
FileInputStream bpin = new FileInputStream (file);
|
bpin = new FileInputStream (file);
|
||||||
load (bpin);
|
load (bpin);
|
||||||
bpin.close ();
|
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
System.err.println ("Error reading properties from file "+file+": "+x);
|
System.err.println ("Error reading properties from file "+file+": "+x);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
bpin.close ();
|
||||||
|
} catch (Exception ignore) {}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public synchronized void load (InputStream in) throws IOException {
|
||||||
|
newProps = defaultProps == null ?
|
||||||
|
new Properties () : new Properties (defaultProps);
|
||||||
|
super.load (in);
|
||||||
lastread = System.currentTimeMillis ();
|
lastread = System.currentTimeMillis ();
|
||||||
props = newProps;
|
props = newProps;
|
||||||
newProps = null;
|
newProps = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to load(), but adds to the existing properties instead
|
||||||
|
* of discarding them.
|
||||||
|
*/
|
||||||
|
public synchronized void add (InputStream in) throws IOException {
|
||||||
|
super.load (in);
|
||||||
|
lastread = System.currentTimeMillis ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This should not be used directly if properties are read from file,
|
* This should not be used directly if properties are read from file,
|
||||||
* otherwise changes will be lost whe the file is next modified.
|
* otherwise changes will be lost whe the file is next modified.
|
||||||
|
|
Loading…
Add table
Reference in a new issue