01: package org.objectweb.celtix.tools.utils;
02:
03: import java.io.*;
04: import java.util.*;
05: import org.objectweb.celtix.common.util.StringUtils;
06:
07: public class PropertyUtil {
08: private static final String DEFAULT_DELIM = "=";
09: 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(
13: new InputStreamReader(is));
14: String line = br.readLine();
15: while (!StringUtils.isEmpty(line)) {
16: StringTokenizer st = new StringTokenizer(line, delim);
17: String key = null;
18: String value = null;
19: if (st.hasMoreTokens()) {
20: key = st.nextToken().trim();
21: }
22: if (st.hasMoreTokens()) {
23: value = st.nextToken().trim();
24: }
25:
26: maps.put(key, value);
27:
28: line = br.readLine();
29: }
30: br.close();
31: }
32:
33: public void load(InputStream is) throws IOException {
34: load(is, DEFAULT_DELIM);
35: }
36:
37: public String getProperty(String key) {
38: return this .maps.get(key);
39: }
40:
41: public Map<String, String> getMaps() {
42: return this.maps;
43: }
44: }
|