- java.lang.Object
-
- io.github.mmm.cli.io.impl.CliConsoleImpl
-
- All Implemented Interfaces:
CliConsole,Flushable
public class CliConsoleImpl extends Object implements CliConsole
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 Constructor Description CliConsoleImpl()The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CliOutcreateOut(CliLogLevel logLevel)voidflush()LocalegetLocale()CliLogLevelgetLogLevel()protected PrintStreamgetOut(CliLogLevel logLevel)May be overridden to change defaults (e.g.protected StringgetOutPrefix(CliLogLevel logLevel)May be overridden to change style (e.g.PrintStreamgetStdErr()PrintStreamgetStdOut()CliInin()booleanisPrintStacktrace(CliLogLevel logLevel)CliOutout(CliLogLevel logLevel)voidsetIn(CliIn in)voidsetIn(BufferedReader stdIn)voidsetLocale(Locale locale)voidsetLogLevel(CliLogLevel level)voidsetStdErr(PrintStream stdErr)voidsetStdOut(PrintStream stdOut)
-
-
-
Method Detail
-
getStdOut
public PrintStream getStdOut()
- Specified by:
getStdOutin interfaceCliConsole- Returns:
- the
PrintStreamto use as standard output. Defaults toSystem.out.
-
setStdOut
public void setStdOut(PrintStream stdOut)
- Parameters:
stdOut- the new value ofgetStdOut().
-
getStdErr
public PrintStream getStdErr()
- Specified by:
getStdErrin interfaceCliConsole- Returns:
- the
PrintStreamto use as standard error. Defaults toSystem.err.
-
setStdErr
public void setStdErr(PrintStream stdErr)
- Parameters:
stdErr- new value ofgetStdErr().
-
getLogLevel
public CliLogLevel getLogLevel()
- Specified by:
getLogLevelin interfaceCliConsole- Returns:
- the current
CliLogLevelof this console.
-
setLogLevel
public void setLogLevel(CliLogLevel level)
- Parameters:
level- new value ofgetLogLevel().
-
setLocale
public void setLocale(Locale locale)
- Parameters:
locale- new value ofgetLocale().
-
in
public CliIn in()
- Specified by:
inin interfaceCliConsole- Returns:
- the
CliInto read input values.
-
setIn
public void setIn(BufferedReader stdIn)
- Parameters:
stdIn- the standard input used to read user input from.
-
out
public CliOut out(CliLogLevel logLevel)
- Specified by:
outin interfaceCliConsole- Parameters:
logLevel- theCliLogLevel.- Returns:
- the
CliOutfor the givenCliLogLevel.
-
createOut
protected CliOut createOut(CliLogLevel logLevel)
- Parameters:
logLevel- theCliLogLevelto log to.- Returns:
- the
CliOut.
-
getOut
protected PrintStream getOut(CliLogLevel logLevel)
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
protected String getOutPrefix(CliLogLevel logLevel)
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
public boolean isPrintStacktrace(CliLogLevel logLevel)
- Parameters:
logLevel- theCliLogLevelto log to.- Returns:
trueif stacktraces should be printed.
-
flush
public void flush()
- Specified by:
flushin interfaceCliConsole- Specified by:
flushin interfaceFlushable
-
-