01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.tools.util;
19:
20: import java.io.BufferedReader;
21: import java.io.IOException;
22: import java.io.InputStream;
23: import java.io.InputStreamReader;
24: import java.util.HashMap;
25: import java.util.Map;
26: import java.util.StringTokenizer;
27:
28: import org.apache.cxf.common.util.StringUtils;
29:
30: public class PropertyUtil {
31: private static final String DEFAULT_DELIM = "=";
32: private Map<String, String> maps = new HashMap<String, String>();
33:
34: public void load(InputStream is, String delim) throws IOException {
35: BufferedReader br = new BufferedReader(
36: new InputStreamReader(is));
37: String line = br.readLine();
38: while (!StringUtils.isEmpty(line)) {
39: StringTokenizer st = new StringTokenizer(line, delim);
40: String key = null;
41: String value = null;
42: if (st.hasMoreTokens()) {
43: key = st.nextToken().trim();
44: }
45: if (st.hasMoreTokens()) {
46: value = st.nextToken().trim();
47: }
48:
49: maps.put(key, value);
50:
51: line = br.readLine();
52: }
53: br.close();
54: }
55:
56: public void load(InputStream is) throws IOException {
57: load(is, DEFAULT_DELIM);
58: }
59:
60: public String getProperty(String key) {
61: return this .maps.get(key);
62: }
63:
64: public Map<String, String> getMaps() {
65: return this.maps;
66: }
67: }
|