1 /*****************************************************/
2 /* This java file is a part of the */
4 /* - Plouf's Java IRC Client - */
6 /* Copyright (C) 2002 - 2004 Philippe Detournay */
8 /* All contacts : theplouf@yahoo.com */
10 /* PJIRC is free software; you can redistribute */
11 /* it and/or modify it under the terms of the GNU */
12 /* General Public License as published by the */
13 /* Free Software Foundation; version 2 or later of */
16 /* PJIRC is distributed in the hope that it will */
17 /* be useful, but WITHOUT ANY WARRANTY; without */
18 /* even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
20 /* General Public License for more details. */
22 /* You should have received a copy of the GNU */
23 /* General Public License along with PJIRC; if */
24 /* not, write to the Free Software Foundation, */
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
26 /* MA 02111-1307 USA */
28 /*****************************************************/
32 import java.io.BufferedReader;
33 import java.io.InputStream;
34 import java.io.InputStreamReader;
35 import java.util.Hashtable;
38 * Parameter provider from a text stream.
40 public class StreamParameterProvider implements ParameterProvider {
41 private Hashtable _table;
44 * Create a new StreamParameterProvider loading the given input stream.
47 * the input stream to load from. If is is null, then the parameter
50 public StreamParameterProvider(InputStream is) {
51 _table = new Hashtable();
56 BufferedReader reader = new BufferedReader(new InputStreamReader(is));
57 String line = reader.readLine();
58 while (line != null) {
60 if (line.length() > 0) {
61 if (line.charAt(0) != '#') {
65 line = reader.readLine();
68 } catch (Exception ex) {
73 private void parse(String str) {
74 int pos = str.indexOf('=');
77 String before = str.substring(0, pos).trim().toLowerCase(java.util.Locale.ENGLISH);
78 String after = str.substring(pos + 1).trim();
79 _table.put(before, after);
83 public String getParameter(String name) {
84 return (String) _table.get(name.toLowerCase(java.util.Locale.ENGLISH));