java.lang.Object
io.github.mmm.cli.io.impl.CliConsoleImpl
- All Implemented Interfaces:
CliConsole,Flushable
Interface for a console as standard in, out, and err. Allows to read user-input and output messages or errors. It is
similar to a logger but specific for the needs of command-line-interfaces.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected CliOutcreateOut(CliLogLevel logLevel) voidflush()protected PrintStreamgetOut(CliLogLevel logLevel) May be overridden to change defaults (e.g.protected StringgetOutPrefix(CliLogLevel logLevel) May be overridden to change style (e.g.in()booleanisPrintStacktrace(CliLogLevel logLevel) out(CliLogLevel logLevel) voidvoidsetIn(BufferedReader stdIn) voidvoidsetLogLevel(CliLogLevel level) voidsetStdErr(PrintStream stdErr) voidsetStdOut(PrintStream stdOut)
-
Constructor Details
-
CliConsoleImpl
public CliConsoleImpl()The constructor.
-
-
Method Details
-
getStdOut
- Specified by:
getStdOutin interfaceCliConsole- Returns:
- the
PrintStreamto use as standard output. Defaults toSystem.out.
-
setStdOut
- Parameters:
stdOut- the new value ofgetStdOut().
-
getStdErr
- Specified by:
getStdErrin interfaceCliConsole- Returns:
- the
PrintStreamto use as standard error. Defaults toSystem.err.
-
setStdErr
- Parameters:
stdErr- new value ofgetStdErr().
-
getLogLevel
- Specified by:
getLogLevelin interfaceCliConsole- Returns:
- the current
CliLogLevelof this console.
-
setLogLevel
- Parameters:
level- new value ofgetLogLevel().
-
getLocale
- Returns:
- the
Localeto use.
-
setLocale
- Parameters:
locale- new value ofgetLocale().
-
in
- Specified by:
inin interfaceCliConsole- Returns:
- the
CliInto read input values.
-
setIn
- Parameters:
in- the new value ofin().
-
setIn
- Parameters:
stdIn- the standard input used to read user input from.
-
out
- Specified by:
outin interfaceCliConsole- Parameters:
logLevel- theCliLogLevel.- Returns:
- the
CliOutfor the givenCliLogLevel.
-
createOut
- Parameters:
logLevel- theCliLogLevelto log to.- Returns:
- the
CliOut.
-
getOut
May be overridden to change defaults (e.g. do log warnings on standard out instead of standard error).- Parameters:
logLevel- theCliLogLevelto log to. May benull.- Returns:
- the
PrintStreamto use for the givenCliLogLevel.
-
getOutPrefix
May be overridden to change style (e.g. "[DEBUG] " instead of "DEBUG: ") or to do localization.- Parameters:
logLevel- theCliLogLevelto log to.- Returns:
- the prefix to log for the given
CliLogLevel.
-
isPrintStacktrace
- Parameters:
logLevel- theCliLogLevelto log to.- Returns:
trueif stacktraces should be printed.
-
flush
public void flush()- Specified by:
flushin interfaceCliConsole- Specified by:
flushin interfaceFlushable
-