1 package org.objectweb.celtix.tools.utils; 2 3 import java.io.*; 4 import java.util.*; 5 import org.objectweb.celtix.common.util.StringUtils; 6 7 public class PropertyUtil { 8 private static final String DEFAULT_DELIM = "="; 9 private Map<String , String > maps = new HashMap<String , String >(); 10 11 public void load(InputStream is, String delim) throws IOException { 12 BufferedReader br = new BufferedReader(new InputStreamReader(is)); 13 String line = br.readLine(); 14 while (!StringUtils.isEmpty(line)) { 15 StringTokenizer st = new StringTokenizer(line, delim); 16 String key = null; 17 String value = null; 18 if (st.hasMoreTokens()) { 19 key = st.nextToken().trim(); 20 } 21 if (st.hasMoreTokens()) { 22 value = st.nextToken().trim(); 23 } 24 25 maps.put(key, value); 26 27 line = br.readLine(); 28 } 29 br.close(); 30 } 31 32 public void load(InputStream is) throws IOException { 33 load(is, DEFAULT_DELIM); 34 } 35 36 public String getProperty(String key) { 37 return this.maps.get(key); 38 } 39 40 public Map<String , String > getMaps() { 41 return this.maps; 42 } 43 } 44 | Popular Tags |