fc.io
Class Prompt

java.lang.Object
  extended by fc.io.Prompt

public class Prompt
extends Object

Prompts a user for input.

Thread safety: This class is not thread safe and higher level synchronization (or multiple instances of this class) should be used.

Version:
1.0 12/15/2001

Constructor Summary
Prompt()
          Constructs a fallback object, using System.in, System.out for the input, output and error streams.
Prompt(InputStream in, PrintStream out, PrintStream err)
          Constructs the object using the specified input and output streams.
Prompt(Reader in, PrintWriter out, PrintWriter err)
          Constructs the object using the specified input and output writers.
 
Method Summary
 String ask(String str)
          Calls ask(String, boolean) so that a newline is not shown after the question shown to the user.
 String ask(String str, boolean newline)
          Shows the specified string to the user shows the input prompt to the user (to indicate the user's input is expected).
 String ask(String str, String fallback)
          Calls ask(String, String, boolean) so that a newline is not shown after the question shown to the user.
 String ask(String str, String fallback, boolean newline)
          Shows the specified string to the user shows the input prompt to the user (to indicate the user's input is expected).
 String getLastLine()
          Gets the latest input line that has been read.
static void main(String[] args)
           
 void setError(PrintStream err)
           
 void setError(PrintWriter err)
           
 void setInput(InputStream in)
           
 void setInput(Reader in)
           
 void setOutput(PrintStream out)
           
 void setOutput(PrintWriter out)
           
 void write(String str)
          Immediately writes a string to the output.
 void writeln(String str)
          Immediately writes the specified string as a new line, to the output.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Prompt

public Prompt(Reader in,
              PrintWriter out,
              PrintWriter err)
Constructs the object using the specified input and output writers.

Parameters:
in - the BufferedReader to use for input
out - the PrintWriter to use for output
err - the PrintWriter to use for errors

Prompt

public Prompt(InputStream in,
              PrintStream out,
              PrintStream err)
Constructs the object using the specified input and output streams.

Parameters:
in - the BufferedReader to use for input
out - the PrintWriter to use for output
err - the PrintWriter to use for errors

Prompt

public Prompt()
Constructs a fallback object, using System.in, System.out for the input, output and error streams.

Method Detail

ask

public String ask(String str,
                  boolean newline)
Shows the specified string to the user shows the input prompt to the user (to indicate the user's input is expected). Keeps looping and asking the same question until a non-empty response has been typed by the user, then returns that response.

Parameters:
str - the string to show to the user
newline - whether to print a newline after the string

ask

public String ask(String str)
Calls ask(String, boolean) so that a newline is not shown after the question shown to the user.


ask

public String ask(String str,
                  String fallback,
                  boolean newline)
Shows the specified string to the user shows the input prompt to the user (to indicate the user's input is expected). Returns the fallback string if a empty response has been typed by the user, else returns the user response.

Parameters:
str - the string to show to the user
fallback - response to return if the user types in an empty response (typically by simply hitting a newline)
newline - whether to print a newline after showing the specified string to the user

ask

public String ask(String str,
                  String fallback)
Calls ask(String, String, boolean) so that a newline is not shown after the question shown to the user.


write

public void write(String str)
Immediately writes a string to the output. The prompt is written before the string.


writeln

public void writeln(String str)
Immediately writes the specified string as a new line, to the output. The prompt is written before the string.


getLastLine

public String getLastLine()
Gets the latest input line that has been read. Can return the same line multiple times if no new lines have been read since the last time this method was called. Returns null if no line has been read so far.


setInput

public void setInput(Reader in)

setInput

public void setInput(InputStream in)

setOutput

public void setOutput(PrintStream out)

setOutput

public void setOutput(PrintWriter out)

setError

public void setError(PrintStream err)

setError

public void setError(PrintWriter err)

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception