01: package org.lateralnz.common.wrapper;
02:
03: import java.io.FileInputStream;
04: import java.io.FileOutputStream;
05: import java.io.IOException;
06: import java.util.Properties;
07:
08: import org.lateralnz.common.util.IOUtils;
09:
10: public class PropertiesWrapper extends Properties {
11:
12: private String filename = null;
13:
14: public PropertiesWrapper() {
15: super ();
16: }
17:
18: public PropertiesWrapper(String filename) throws IOException {
19: super ();
20: init(filename);
21: }
22:
23: public PropertiesWrapper(String filename, Properties props)
24: throws IOException {
25: super (props);
26: init(filename);
27: }
28:
29: private void init(String filename) throws IOException {
30: this .filename = filename;
31: load();
32: }
33:
34: public synchronized Object put(Object key, Object value) {
35: return super .put(key, value);
36: }
37:
38: public synchronized void load() throws IOException {
39: FileInputStream fis = null;
40: try {
41: fis = new FileInputStream(filename);
42: this .load(fis);
43: } finally {
44: IOUtils.close(fis);
45: }
46: }
47:
48: public synchronized void save() throws IOException {
49: FileOutputStream fos = null;
50: try {
51: fos = new FileOutputStream(filename);
52: this .store(fos, "");
53: } finally {
54: IOUtils.close(fos);
55: }
56: }
57: }
|