/*
 * =============================================================================
 * ReadTextFromConcole.java: Demonstrate how to read text from standard input.
 * The program will read lines of text from the command prompt until either the
 * string "exit" or "quit" is entered.
 * 
 * Written By: Mark Austin                                          October 2005 
 * =============================================================================
 */
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class ReadTextFromConsole {

    // Echo line of input....

    public static void printLine(String str) {
        System.out.println("...echo input: " + str );
    }

    // Read line of text from console (keyboard input)....

    public static String getTextFromConsole() {
       String inLine = "";

       // Create buffered reader for keyboard input stream....

       BufferedReader inStream = new BufferedReader (
                                 new InputStreamReader(System.in));

       // Try to read input from keyboard ....

       try {
          inLine = inStream.readLine();
       } catch (IOException e) {
          System.out.println("IOException: " + e);
       }

       return inLine;
    }

    /* Entry point to the program.... */

    public static void main(String[] args) {
       String sLine = "";

         while ( ( sLine.equalsIgnoreCase("quit") == false ) &&
                 ( sLine.equalsIgnoreCase("exit") == false) ) {

            // Print console prompt ...

               System.out.print("prompt >> ");

            // Read and echo line of keyboard input ....

               sLine = getTextFromConsole();
               printLine( sLine );
         }
    }
}
