001package edu.pdx.cs410J.core;
002
003import java.io.*;
004
005/**
006 * This program reads text from the console until the user enters
007 * <code>-1</code> at which point it prints what the user has entered.
008 * It demonstrates the <code>BufferedReader</code>,
009 * <code>InputStreamReader</code>, and <code>StringWriter</code>
010 * classes.
011 */
012public class ReadFromConsole {
013
014  public static void main(String[] args) {
015    InputStreamReader isr = new InputStreamReader(System.in);
016    BufferedReader br = new BufferedReader(isr);
017    StringWriter text = new StringWriter();
018
019    while (true) {
020      try {
021        // Read a line from the console
022        String line = br.readLine();
023
024        if(line.equals("-1")) {
025          // All done with input
026          break;
027
028        } else {
029          text.write(line + " ");
030        }
031
032      } catch (IOException ex) {
033        System.err.println("** " + ex);
034        System.exit(1);
035      }
036    }
037
038    // Print out what was entered
039    System.out.println(text);
040  }
041
042}