KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > groovy > sandbox > ui > JavaPrompt


1 package org.codehaus.groovy.sandbox.ui;
2
3 import java.io.BufferedReader JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.InputStreamReader JavaDoc;
6 import java.io.InputStream JavaDoc;
7 import java.io.PrintStream JavaDoc;
8
9 /**
10  * Pure Java prompt using just System.in.
11  */

12 public class JavaPrompt implements Prompt
13 {
14     private String JavaDoc prompt;
15     private BufferedReader JavaDoc input;
16     private final PrintStream JavaDoc out;
17     private final PrintStream JavaDoc err;
18
19     public JavaPrompt(InputStream JavaDoc in, PrintStream JavaDoc out, PrintStream JavaDoc err)
20     {
21         this.out = out;
22         this.err = err;
23         this.input = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(in));
24     }
25
26     public JavaPrompt()
27     {
28         this(System.in, System.out, System.err);
29     }
30
31     public String JavaDoc readLine() throws IOException JavaDoc
32     {
33         out.print(prompt);
34         out.flush();
35         return input.readLine();
36     }
37
38     public String JavaDoc getPrompt()
39     {
40         return prompt;
41     }
42
43     public void setPrompt(String JavaDoc prompt)
44     {
45         this.prompt = prompt;
46     }
47
48     public void setCompleter(Completer completer)
49     {
50         // completer not supported
51
}
52
53     public void close()
54     {
55         try
56         {
57             input.close();
58         }
59         catch (IOException JavaDoc e)
60         {
61             e.printStackTrace(err);
62         }
63     }
64 }
65
Popular Tags