| 1 package org.lateralnz.common.wrapper; 2 3 import java.io.FileInputStream ; 4 import java.io.FileOutputStream ; 5 import java.io.IOException ; 6 import java.util.Properties ; 7 8 import org.lateralnz.common.util.IOUtils; 9 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) throws IOException { 24 super(props); 25 init(filename); 26 } 27 28 private void init(String filename) throws IOException { 29 this.filename = filename; 30 load(); 31 } 32 33 public synchronized Object put(Object key, Object value) { 34 return super.put(key, value); 35 } 36 37 public synchronized void load() throws IOException { 38 FileInputStream fis = null; 39 try { 40 fis = new FileInputStream (filename); 41 this.load(fis); 42 } 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 } 54 finally { 55 IOUtils.close(fos); 56 } 57 } 58 } | Popular Tags |