KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > tools > utils > PropertyUtil


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 JavaDoc DEFAULT_DELIM = "=";
9     private Map<String JavaDoc, String JavaDoc> maps = new HashMap<String JavaDoc, String JavaDoc>();
10
11     public void load(InputStream is, String JavaDoc delim) throws IOException {
12         BufferedReader br = new BufferedReader(new InputStreamReader(is));
13         String JavaDoc line = br.readLine();
14         while (!StringUtils.isEmpty(line)) {
15             StringTokenizer st = new StringTokenizer(line, delim);
16             String JavaDoc key = null;
17             String JavaDoc 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 JavaDoc getProperty(String JavaDoc key) {
37         return this.maps.get(key);
38     }
39
40     public Map<String JavaDoc, String JavaDoc> getMaps() {
41         return this.maps;
42     }
43 }
44
Popular Tags