2 import java.io.StreamTokenizer;
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7 import java.io.PipedInputStream;
8 import java.io.PipedOutputStream;
9 import java.io.PrintWriter;
10 import java.io.Reader;
11 import java.io.StreamTokenizer;
12 import java.util.ArrayList;
13 import java.util.List;
21 * Created: Tue Feb 13 15:40:34 2001
23 * @author <a href="mailto: "</a>
27 public class CommandStream extends StreamTokenizer implements Protocol {
29 public CommandStream (BufferedReader in){
36 public List nextCommand() {
38 List commandLine = new ArrayList();
42 int token = nextToken();
44 while (token != TT_EOL) {
49 throw new IOException("EOF occurred reading command stream.");
54 commandLine.add(sval);
58 commandLine.add(String.valueOf((char)token));
65 if (commandLine.size() < 3) {
66 if (commandLine.size() > 0) {
67 JDE.commandResult(new Integer(-1), "Malformed command: size=" + commandLine.size(),
69 JDE.debug(COMMANDS, commandLine.toString());
71 commandLine = nextCommand();
74 catch (IOException ex) {
82 * Sets the syntax of the command stream. We want the input to be broken
83 * into lines, with whitespaces separating tokens
85 private void setSyntax() {
87 eolIsSignificant(true);
88 whitespaceChars('\u0000', '\u0020');
89 wordChars('\u0021', '\u00ff');
93 public static void main (String[] args) {
95 PrintWriter out = new PrintWriter(System.out);
96 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
97 CommandStream commandStream = new CommandStream(in);
101 List command = commandStream.nextCommand();
102 while (command != null && ! ((String) command.get(2)).startsWith("qu")) {
104 int n = command.size();
105 for (int i = 0; i<n; i++) {
106 out.println(command.get(i));
111 command = commandStream.nextCommand();
117 private final Reader m_reader;
119 // ----------------------------------------
120 // Fix for bug 4809647
121 // ----------------------------------------
125 } catch (IOException exc) {
126 throw new ExceptionInInitializerError(exc);
131 * You must call <code>StdIn.fix()</code> once before using
132 <code>System.in</code>.
134 private static final class StdIn
136 private static InputStream in;
137 private static PipedInputStream pis;
138 private static PipedOutputStream pos;
140 private static Thread pump = new Thread("StdIn Pump")
145 byte[] buf = new byte[5120];
149 int available = in.available();
151 if (available == 0) {
156 int howMany = Math.min(buf.length, available);
159 //This works because we asked how many are there
160 in.read(buf, 0, howMany);
161 pos.write(buf, 0, howMany);
162 // JDE.debug(JDE_PIPE, "Pumped " + howMany + " bytes to stdin, " +
163 // "starting with '" +
164 // new String(buf, 0, Math.min(20, howMany)) + "...'");
168 catch (Exception ex) {
169 ex.printStackTrace();
176 * Nobody can create an instance of this class
181 * This method replaces System.in and workarounds bug
184 public synchronized static void fix()
192 pos = new PipedOutputStream();
193 pis = new PipedInputStream(pos);
195 pump.setDaemon(true);
196 pump.setPriority(Thread.MIN_PRIORITY);
200 // ----------------------------------------
201 // End Fix for bug 4809647
202 // ----------------------------------------
206 * $Log: CommandStream.java,v $
207 * Revision 1.5 2004/12/24 16:05:12 troy
208 * Add window to display threads and stacks
210 * Revision 1.4 2003/04/29 16:51:56 troy
211 * Initial version of GUI. Includes display of local variables.
213 * Revision 1.3 2003/01/08 07:03:08 paulk
214 * Remove carriage returns.
216 * Revision 1.2 2003/01/08 06:53:38 paulk
217 * Integrate Petter Mahlen's updates.
221 // End of CommandStream.java