KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lateralnz > common > wrapper > PropertiesWrapper


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