Class LineReader


  • public class LineReader
    extends java.lang.Object
    Class containing methods for reading strings from the user (standard input). Both normal and 'masked' reads are provided - the latter is useful for reading passwords in such a way that they don't appear on the screen.
    Since:
    27 Nov 2006
    Author:
    Mark Taylor
    • Constructor Summary

      Constructors 
      Constructor Description
      LineReader()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String readMaskedString​(java.lang.String prompt, java.io.PrintStream outStrm)
      Reads a line of text from the user without it being visible to onlookers.
      static java.lang.String readString​(java.lang.String prompt, java.io.PrintStream outStrm)
      Reads a line of text from the user.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LineReader

        public LineReader()
    • Method Detail

      • readString

        public static java.lang.String readString​(java.lang.String prompt,
                                                  java.io.PrintStream outStrm)
                                           throws java.io.IOException
        Reads a line of text from the user.
        Parameters:
        prompt - short line of text to act as a prompt
        outStrm - print stream to use for prompt output - typically System.err
        Throws:
        java.io.IOException
      • readMaskedString

        public static java.lang.String readMaskedString​(java.lang.String prompt,
                                                        java.io.PrintStream outStrm)
                                                 throws java.io.IOException
        Reads a line of text from the user without it being visible to onlookers. Suitable utility method for soliciting passwords.
        Parameters:
        prompt - short line of text to act as a prompt
        outStrm - print stream to use for output - typically System.err
        Returns:
        string entered by user
        Throws:
        java.io.IOException