Debian Codegraph @

src/main/java/org/freehep/util/io/PromptInputStream.java

raw
1 // Copyright 2002, FreeHEP.
2 package org.freehep.util.io;
3
4 import java.io.IOException;
5 import java.io.InputStream;
6
7 /**
8 * The PromptInputStream reads from an inputstream until it reads any prompt for
9 * which a listener is added. The listener is informed that the prompt is found.
10 * The route which contains the prompt is supplied as a parameter to the
11 * listener. Returning from the prompt listener without reading the route to its
12 * end will allow the main stream to read it.
13 *
14 * The implementation of this class is based on the RoutedInputStream.
15 *
16 * @author Mark Donszelmann
17 * @version $Id: PromptInputStream.java 8584 2006-08-10 23:06:37Z duns $
18 */
19 public class PromptInputStream extends RoutedInputStream {
20
21 /**
22 * Craete a Prompt input stream.
23 *
24 * @param input stream to read
25 */
26 public PromptInputStream(InputStream input) {
27 super(input);
28 }
29
30 /**
31 * Add a prompt listener for given prompt.
32 *
33 * @param prompt prompt to listen for
34 * @param listener listener to be informed
35 */
36 public void addPromptListener(String prompt, PromptListener listener) {
37 final PromptListener promptListener = listener;
38 addRoute(prompt, prompt, new RouteListener() {
39 public void routeFound(RoutedInputStream.Route input)
40 throws IOException {
41 promptListener.promptFound(input);
42 }
43 });
44 }
45 }