Package de.audioattack.io
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 ofConsoleas easy as usingPrintStream.- Since:
- 1.1.0
-
-
Constructor Summary
Constructors Constructor Description ConsolePrintDecorator(Console console)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConsolePrintDecoratorappend(char c)Appends the specified character.ConsolePrintDecoratorappend(CharSequence charSequence)Appends the specified character sequence.ConsolePrintDecoratorappend(CharSequence charSequence, int start, int end)Appends a subsequence of the specified character sequence.booleancheckError()Flushes the underlying stream and checks its error state.voidflush()Flushes this ConsoleStringDecorator by writing any buffered output.ConsolePrintDecoratorformat(String fmt, Object... args)Writes formatted String.ConsolePrintDecoratorformat(Locale locale, String fmt, Object... args)Writes formatted String.voidprint(boolean b)Prints a boolean value.voidprint(char c)Prints a character.voidprint(char[] s)Prints a character array.voidprint(double d)Prints a double-precision floating-point number.voidprint(float f)Prints a floating-point number.voidprint(int i)Prints an integer.voidprint(long l)Prints a long integer.voidprint(Object o)Prints an object.voidprint(String s)Prints a string.ConsolePrintDecoratorprintf(String fmt, Object... args)Convenience method which writes formatted String.ConsolePrintDecoratorprintf(Locale locale, String fmt, Object... args)Convenience method which writes formatted String.voidprintln()Terminates the current line by writing the line separator string.voidprintln(boolean b)Prints a boolean value and then terminates the line.voidprintln(char c)Prints a character and then terminates the line.voidprintln(char[] s)Prints a character array and then terminates the line.voidprintln(double d)Prints a double-precision floating-point number and then terminates the line.voidprintln(float f)Prints a floating-point number and then terminates the line.voidprintln(int i)Prints an integer and then terminates the line.voidprintln(long l)Prints a long integer and then terminates the line.voidprintln(Object o)Prints an object and then terminates the line.voidprintln(String s)Prints a string and then terminates the line.Readerreader()Gets theReaderassociated with the console.StringreadLine()Reads single line.StringreadLine(String fmt, Object... args)Writes formatted prompt and reads single line.char[]readPassword()Reads password.char[]readPassword(String fmt, Object... args)Writes formatted prompt and reads password.PrintWriterwriter()Gets thePrintWriterassociated with the console.
-
-
-
Constructor Detail
-
ConsolePrintDecorator
public ConsolePrintDecorator(Console console)
Constructor.- Parameters:
console- the console to which data will be written
-
-
Method Detail
-
reader
public Reader reader()
Gets theReaderassociated with the console.- Specified by:
readerin interfaceConsole- Returns:
- the reader
- See Also:
Console.reader()
-
writer
public PrintWriter writer()
Gets thePrintWriterassociated with the console.- Specified by:
writerin interfaceConsole- Returns:
- the writer
- See Also:
Console.writer()
-
format
public ConsolePrintDecorator format(String fmt, Object... args)
Writes formatted String.- Specified by:
formatin interfaceConsole- Parameters:
fmt- format Stringargs- arguments to replace format specifiers in format String- Returns:
- this ConsolePrintDecorator
- See Also:
Console.format(String, Object...)
-
format
public ConsolePrintDecorator format(Locale locale, String fmt, Object... args)
Writes formatted String.- Parameters:
locale- The locale to apply during formatting. If it isnullthen no localization is applied.fmt- format Stringargs- 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 isnullthen no localization is applied.fmt- format Stringargs- 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:
printfin interfaceConsole- Parameters:
fmt- format Stringargs- arguments to replace format specifiers in format String- Returns:
- this ConsolePrintDecorator
- See Also:
Console.printf(String, Object...)
-
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:
readLinein interfaceConsole- Parameters:
fmt- format Stringargs- arguments to replace format specifiers in format String- Returns:
- the line
- See Also:
Console.readLine(String, Object...)
-
readLine
public String readLine()
Reads single line.- Specified by:
readLinein interfaceConsole- Returns:
- the line
- See Also:
Console.readLine()
-
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:
readPasswordin interfaceConsole- Parameters:
fmt- format Stringargs- arguments to replace format specifiers in format String- Returns:
- the password
- See Also:
Console.readPassword(String, Object...)
-
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:
readPasswordin interfaceConsole- Returns:
- the password
- See Also:
Console.readPassword()
-
flush
public void flush() throws IOExceptionFlushes this ConsoleStringDecorator by writing any buffered output.- Specified by:
flushin interfaceFlushable- Throws:
IOException
-
append
public ConsolePrintDecorator append(CharSequence charSequence)
Appends the specified character sequence.- Specified by:
appendin interfaceAppendable- Parameters:
charSequence- the character sequence to append. IfcharSequenceisnull, 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:
appendin interfaceAppendable- Parameters:
charSequence- the character sequence to append. IfcharSequenceisnull, then characters will be appended as ifcharSequencecontained the four characters "null".start- index of the first character in the subsequenceend- index of the character following the last character in the subsequence
-
append
public ConsolePrintDecorator append(char c)
Appends the specified character.- Specified by:
appendin interfaceAppendable- Parameters:
c- the character to append
-
checkError
public boolean checkError()
Flushes the underlying stream and checks its error state. Error state is set totrueif underlying stream has encountered anIOExceptionother than .InterruptedIOException- Returns:
trueif underlying stream has encountered anIOException, elsefalse
-
-