01: /*
02: * TextlistReader.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.util;
13:
14: import java.io.BufferedReader;
15: import java.io.InputStream;
16: import java.io.InputStreamReader;
17: import java.util.Collection;
18: import java.util.LinkedList;
19: import java.util.List;
20: import workbench.log.LogMgr;
21:
22: /**
23: *
24: * @author support@sql-workbench.net
25: */
26: public class TextlistReader {
27: private List<String> values;
28:
29: /**
30: * Reads each line of the passed input stream into
31: * an element of the internal values collection.
32: * Elements will be trimmed.
33: */
34: public TextlistReader(InputStream in) {
35: try {
36: values = new LinkedList<String>();
37: BufferedReader r = new BufferedReader(
38: new InputStreamReader(in));
39: String line = r.readLine();
40: while (line != null) {
41: values.add(line.trim());
42: line = r.readLine();
43: }
44: //LogMgr.logDebug("TextlistReader.<init>", values.size() + " element read from InputStream");
45: } catch (Exception e) {
46: LogMgr.logError("TestlistReader.<init>",
47: "Error reading input stream", e);
48: } finally {
49: try {
50: in.close();
51: } catch (Throwable th) {
52: }
53: }
54: }
55:
56: public Collection<String> getValues() {
57: return values;
58: }
59:
60: }
|