Class ConsolePrintDecorator

java.lang.Object
de.audioattack.io.ConsolePrintDecorator
All Implemented Interfaces:
Console, Flushable, Appendable

public class ConsolePrintDecorator extends Object implements Console, Flushable, Appendable
Contains convenience methods which make usage of de.audioattack.io.Console as easy as using PrintStream.
Since:
1.1.0
  • Constructor Details

    • ConsolePrintDecorator

      public ConsolePrintDecorator(Console console)
      Constructor.
      Parameters:
      console - the console to which data will be written
  • Method Details

    • reader

      public Reader reader()
      Gets a Reader associated with the console. Invoking close() on this object will not close the underlying stream.
      Specified by:
      reader in interface Console
      Returns:
      the reader
      See Also:
    • writer

      public PrintWriter writer()
      Gets a PrintWriter associated with the console. Invoking close() on this object will not close the underlying stream.
      Specified by:
      writer in interface Console
      Returns:
      the writer
      See Also:
    • format

      public ConsolePrintDecorator format(String fmt, Object... args)
      Writes formatted String.
      Specified by:
      format in interface Console
      Parameters:
      fmt - format String
      args - arguments to replace format specifiers in format String
      Returns:
      this ConsolePrintDecorator
      See Also:
    • format

      public ConsolePrintDecorator format(Locale locale, String fmt, Object... args)
      Writes formatted String.
      Parameters:
      locale - The locale to apply during formatting. If it is null then no localization is applied.
      fmt - format String
      args - arguments to replace format specifiers in format String
      Returns:
      this ConsolePrintDecorator
    • print

      public void print(boolean b)
      Prints a boolean value.
      Parameters:
      b - boolean to be printed
    • print

      public void print(char c)
      Prints a character.
      Parameters:
      c - character to be printed
    • print

      public void print(char[] s)
      Prints a character array.
      Parameters:
      s - character array to be printed
    • print

      public void print(double d)
      Prints a double-precision floating-point number.
      Parameters:
      d - double-precision floating-point number to be printed
    • print

      public void print(float f)
      Prints a floating-point number.
      Parameters:
      f - floating-point number to be printed
    • print

      public void print(int i)
      Prints an integer.
      Parameters:
      i - the integer to be printed
    • print

      public void print(long l)
      Prints a long integer.
      Parameters:
      l - the long integer to be printed
    • print

      public void print(Object o)
      Prints an object.
      Parameters:
      o - the object to be printed
    • print

      public void print(String s)
      Prints a string.
      Parameters:
      s - the string to be printed
    • printf

      public ConsolePrintDecorator printf(Locale locale, String fmt, Object... args)
      Convenience method which writes formatted String.
      Parameters:
      locale - The locale to apply during formatting. If it is null then no localization is applied.
      fmt - format String
      args - arguments to replace format specifiers in format String
      Returns:
      this ConsolePrintDecorator
    • printf

      public ConsolePrintDecorator printf(String fmt, Object... args)
      Convenience method which writes formatted String.
      Specified by:
      printf in interface Console
      Parameters:
      fmt - format String
      args - arguments to replace format specifiers in format String
      Returns:
      this ConsolePrintDecorator
      See Also:
    • println

      public void println()
      Terminates the current line by writing the line separator string.
    • println

      public void println(boolean b)
      Prints a boolean value and then terminates the line.
      Parameters:
      b - boolean to be printed
    • println

      public void println(char c)
      Prints a character and then terminates the line.
      Parameters:
      c - character to be printed
    • println

      public void println(char[] s)
      Prints a character array and then terminates the line.
      Parameters:
      s - character array to be printed
    • println

      public void println(double d)
      Prints a double-precision floating-point number and then terminates the line.
      Parameters:
      d - double-precision floating-point number to be printed
    • println

      public void println(float f)
      Prints a floating-point number and then terminates the line.
      Parameters:
      f - floating-point number to be printed
    • println

      public void println(int i)
      Prints an integer and then terminates the line.
      Parameters:
      i - the integer to be printed
    • println

      public void println(long l)
      Prints a long integer and then terminates the line.
      Parameters:
      l - the long integer to be printed
    • println

      public void println(Object o)
      Prints an object and then terminates the line.
      Parameters:
      o - the object to be printed
    • println

      public void println(String s)
      Prints a string and then terminates the line.
      Parameters:
      s - the string to be printed
    • readLine

      public String readLine(String fmt, Object... args)
      Writes formatted prompt and reads single line.
      Specified by:
      readLine in interface Console
      Parameters:
      fmt - format String
      args - arguments to replace format specifiers in format String
      Returns:
      the line
      See Also:
    • readLine

      public String readLine()
      Reads single line.
      Specified by:
      readLine in interface Console
      Returns:
      the line
      See Also:
    • readPassword

      public char[] readPassword(String fmt, Object... args)
      Writes formatted prompt and reads password. Hidden input should be preferred if possible. Implementations which cannot hide input should display a warning that entered text will be visible.
      Specified by:
      readPassword in interface Console
      Parameters:
      fmt - format String
      args - arguments to replace format specifiers in format String
      Returns:
      the password
      See Also:
    • readPassword

      public char[] readPassword()
      Reads password. Hidden input should be preferred if possible. Implementations which cannot hide input should display a warning that entered text will be visible.
      Specified by:
      readPassword in interface Console
      Returns:
      the password
      See Also:
    • flush

      public void flush()
      Flushes this ConsoleStringDecorator by writing any buffered output.
      Specified by:
      flush in interface Flushable
    • append

      public ConsolePrintDecorator append(CharSequence charSequence)
      Appends the specified character sequence.
      Specified by:
      append in interface Appendable
      Parameters:
      charSequence - the character sequence to append. If charSequence is null, then the four characters "null" are appended
    • append

      public ConsolePrintDecorator append(CharSequence charSequence, int start, int end)
      Appends a subsequence of the specified character sequence.
      Specified by:
      append in interface Appendable
      Parameters:
      charSequence - the character sequence to append. If charSequence is null, then characters will be appended as if charSequence contained the four characters "null".
      start - index of the first character in the subsequence
      end - index of the character following the last character in the subsequence
    • append

      public ConsolePrintDecorator append(char c)
      Appends the specified character.
      Specified by:
      append in interface Appendable
      Parameters:
      c - the character to append
    • checkError

      public boolean checkError()
      Flushes the underlying stream and checks its error state. Error state is set to true if underlying stream has encountered an IOException other than .InterruptedIOException
      Returns:
      true if underlying stream has encountered an IOException, else false