Class ConsolePrompt

  • All Implemented Interfaces:
    PromptProvider

    public class ConsolePrompt
    extends java.lang.Object
    implements PromptProvider
    A prompt that is backed by System.console()
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.Console console  
    • Constructor Summary

      Constructors 
      Constructor Description
      ConsolePrompt()
      Creates a new console prompt using the default System.console()
      ConsolePrompt​(java.io.Console console)
      Creates a new console prompt using the specified console
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.io.PrintWriter getPromptWriter()
      Gets the writer to which prompts should be written
      int readKey()
      Reads a single key from the prompts source
      java.lang.String readLine()
      Reads a line from the prompts source
      char[] readSecureLine()
      Reads a line from the prompts source in a secure manner
      boolean supportsSecureReads()
      Whether the provider supports secured reads
      • Methods inherited from class java.lang.Object

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

      • console

        private final java.io.Console console
    • Constructor Detail

      • ConsolePrompt

        public ConsolePrompt()
        Creates a new console prompt using the default System.console()
      • ConsolePrompt

        public ConsolePrompt​(java.io.Console console)
        Creates a new console prompt using the specified console
        Parameters:
        console - Console
    • Method Detail

      • getPromptWriter

        public java.io.PrintWriter getPromptWriter()
        Description copied from interface: PromptProvider
        Gets the writer to which prompts should be written
        Specified by:
        getPromptWriter in interface PromptProvider
        Returns:
        Prompt writer
      • readLine

        public java.lang.String readLine()
        Description copied from interface: PromptProvider
        Reads a line from the prompts source
        Specified by:
        readLine in interface PromptProvider
        Returns:
        Line (or null if unable to read a line)
      • readKey

        public int readKey()
        Description copied from interface: PromptProvider
        Reads a single key from the prompts source
        Specified by:
        readKey in interface PromptProvider
        Returns:
        Key code (or -1 if unable to read a key)
      • readSecureLine

        public char[] readSecureLine()
        Description copied from interface: PromptProvider
        Reads a line from the prompts source in a secure manner
        Specified by:
        readSecureLine in interface PromptProvider
        Returns:
        Line (or null if unable to read a line)
      • supportsSecureReads

        public boolean supportsSecureReads()
        Description copied from interface: PromptProvider
        Whether the provider supports secured reads
        Specified by:
        supportsSecureReads in interface PromptProvider
        Returns:
        True if supported, false otherwise