Flushable
ConsoleProgramConsole
public interface ProgramConsole extends Flushable
Since Console
is final and not an interface, it is
impossible to replace it with a test double. This interface is
identical to that of Console
in Java 6 and, by virtue of being an
interface, is easy to replace with a test double.
Modifier and Type | Method | Description |
---|---|---|
void |
flush() |
Ensures that any buffered output is written out.
|
ProgramConsole |
format(String fmt,
Object... args) |
Prints the message.
|
ProgramConsole |
printf(String format,
Object... args) |
Prints the message.
|
Reader |
reader() |
Returns the underlying reader of this console.
|
String |
readLine() |
Reads a line of input.
|
String |
readLine(String fmt,
Object... args) |
Prints a prompt, and reads a line of input.
|
char[] |
readPassword() |
Reads a password with echoing turned off.
|
char[] |
readPassword(String fmt,
Object... args) |
Prints a prompt, and reads a password with echoing turned off.
|
PrintWriter |
writer() |
Returns the underlying writer of this console.
|
PrintWriter writer()
This behaves exactly like Console.writer()
.
Reader reader()
This behaves exactly like Console.reader()
.
ProgramConsole format(String fmt, Object... args)
This behaves exactly like
Console.format(String, Object...)
.
fmt
- the format string as defined by Formatter
args
- the format string argumentsIllegalFormatException
- if fmt
or args
is
illegal according to the rules of Formatter
ProgramConsole printf(String format, Object... args)
This behaves exactly like
Console.printf(String, Object...)
.
format
- the format string as defined by Formatter
args
- the format string argumentsIllegalFormatException
- if format
or args
is illegal according to the rules of Formatter
String readLine(String fmt, Object... args)
This behaves exactly like
Console.readLine(String, Object...)
.
fmt
- the prompt format string as defined by
Formatter
args
- the format string argumentsnull
if the end of the stream is reachedIllegalFormatException
- if fmt
or args
is
illegal according to the rules of Formatter
IOError
- if an I/O error occursString readLine()
This behaves exactly like Console.readLine()
.
null
if the end of the stream is reachedIOError
- if an I/O error occurschar[] readPassword(String fmt, Object... args)
This behaves exactly like
Console.readPassword(String, Object...)
.
fmt
- the prompt format string as defined by
Formatter
args
- the format string argumentschar
array, not including the line
terminator, or null
if the end of the stream is reachedIllegalFormatException
- if fmt
or args
is
illegal according to the rules of Formatter
IOError
- if an I/O error occurschar[] readPassword()
This behaves exactly like Console.readPassword()
.
char
array, not including the line
terminator, or null
if the end of the stream is reachedIOError
- if an I/O error occursvoid flush()
This behaves exactly like Console.flush()
.