1 package net.sf.tomp.xtcl;
2
3 import java.io.BufferedReader;
4 import java.io.File;
5 import java.io.FileReader;
6 import java.io.InputStreamReader;
7 import java.io.StringReader;
8
9 /***
10 * Used to read command line from various sources, eg. console, file...
11 *
12 * @version 1.0
13 */
14 public class CommandLineReader {
15 /*** Bufferedreader to read command lines from */
16 protected BufferedReader br;
17
18 /***
19 * Creates a new instance of CommandLineReader - from console
20 *
21 * @throws Exception if something fails...
22 */
23 public CommandLineReader() throws Exception {
24 br = new BufferedReader(new InputStreamReader(System.in));
25 }
26
27 /***
28 * Creates a new instance of CommandLineReader - from console
29 *
30 * @param s String to read command line from
31 * @throws Exception if something fails...
32 */
33 public CommandLineReader(String s) throws Exception {
34 br = new BufferedReader(new StringReader(s));
35 }
36
37 /***
38 * Creates a new instance of CommandLineReader - from File
39 *
40 * @param f File to read command line from
41 * @throws Exception if something fails...
42 */
43 public CommandLineReader(File f) throws Exception {
44 br = new BufferedReader(new FileReader(f));
45 }
46
47 /***
48 * Creates a new instance of CommandLineReader - from BufferedReader
49 *
50 * @param b BufferedReader to read command line from
51 * @throws Exception if something fails...
52 */
53 public CommandLineReader(BufferedReader b) throws Exception {
54 br = b;
55 }
56
57 /***
58 * The main and only method Reads next command line
59 *
60 * @return next command line content
61 * @throws Exception if something fails...
62 */
63 public String nextCommandLine() throws Exception {
64 String r = br.readLine();
65
66
67 return r;
68 }
69 }
70
71
72
73
74
75
76
77
78
79
80