View Javadoc

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          //System.err.println("nextCommandLine()->["+r+"]");
67          return r;
68      }
69  }
70  
71  /*
72   * The contents of this file are subject to the Mozilla Public License Version
73   * 1.1 (the "License"); you may not use this file except in compliance with the
74   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
75   * Software distributed under the License is distributed on an "AS IS" basis,
76   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
77   * the specific language governing rights and limitations under the License. The
78   * Original Code is: all this file. The Initial Developer of the Original Code
79   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
80   */