Package org.codehaus.groovy.tools.shell
Class IO
java.lang.Object
org.codehaus.groovy.tools.shell.IO
- All Implemented Interfaces:
Closeable,AutoCloseable
Container for input/output handles.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classVerbosity for simple logging: QUIET, INFO, VERBOSE, DEBUG -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal booleanWhether standard output can render ANSI escape sequences, throughgetAnsiOut(): the IO comes fromforConsole(), JLine's Jansi is on the class path, and standard output is a terminal (or thejansi.modesystem property isforce).final PrintWriterPreferred error output writer.final OutputStreamRaw error output stream.final ReaderPreferred input reader.final InputStreamRaw input stream.final PrintWriterPreferred output writer.final OutputStreamRaw output stream. -
Constructor Summary
ConstructorsConstructorDescriptionIO()Construct a new IO container using system streams, with plain writers.IO(InputStream inputStream, OutputStream outputStream, OutputStream errorStream) Construct a new IO container, with plain writers on the given streams. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close all streams.voidflush()Flush both output streams.static IOCreates an IO container on the system streams whosegetAnsiOut()renders ANSI escape sequences when standard output is a terminal, through JLine's JansiAnsiConsole.Returns a writer on standard output that renders ANSI escape sequences, opening JLine's Jansi console on the first call.Returns the verbosity level.booleanisDebug()Check if the verbosity level is set toIO.Verbosity.DEBUG.booleanisInfo()Check if the verbosity level is set toIO.Verbosity.INFO.booleanisQuiet()Check if the verbosity level is set toIO.Verbosity.QUIET.booleanCheck if the verbosity level is set toIO.Verbosity.VERBOSE.voidsetVerbosity(IO.Verbosity verbosity) Set the verbosity level.protected PrintWritertryConstructRenderWriter(OutputStream stream) Attempts to create an ANSI-aware writer for the supplied stream.
-
Field Details
-
inputStream
Raw input stream. -
outputStream
Raw output stream. -
errorStream
Raw error output stream. -
in
Preferred input reader. -
out
Preferred output writer. -
err
Preferred error output writer. -
ansiSupported
public final boolean ansiSupportedWhether standard output can render ANSI escape sequences, throughgetAnsiOut(): the IO comes fromforConsole(), JLine's Jansi is on the class path, and standard output is a terminal (or thejansi.modesystem property isforce). This is decided without opening the console.outanderrare always plain.
-
-
Constructor Details
-
IO
Construct a new IO container, with plain writers on the given streams. -
IO
public IO()Construct a new IO container using system streams, with plain writers.
-
-
Method Details
-
getAnsiOut
Returns a writer on standard output that renders ANSI escape sequences, opening JLine's Jansi console on the first call. Opening it builds JLine's system terminal, which loads JLine's native library and sends the terminal's probes, so it happens only once something is written in color.- Returns:
- the ANSI writer, or
nullifansiSupportedisfalse, or the console cannot render ANSI after all, orSystem.outhas been replaced since this IO was created
-
tryConstructRenderWriter
Attempts to create an ANSI-aware writer for the supplied stream.Only the JVM's own standard output and error streams can render ANSI, through JLine's Jansi
AnsiConsole, which also enables virtual terminal processing on Windows. The console is opened only when the stream'sjansi.modeisforce, or is notstripand the JVM has a terminal, so output redirected to a file or a pipe never loads JLine.- Parameters:
stream- the output stream to wrap- Returns:
- an ANSI render writer, or
nullif ANSI support is unavailable
-
forConsole
Creates an IO container on the system streams whosegetAnsiOut()renders ANSI escape sequences when standard output is a terminal, through JLine's JansiAnsiConsole.Loggercolors its lines through it, and the console is opened on the first such line.The console writes to the JVM's own standard output, not through
System.out, so call this only whereSystem.outhas not been replaced, such as in a command-line tool'smain. A host that redirects it (Ant, Gradle, an IDE) should useIO().- Returns:
- an IO container that may render ANSI on standard output
-
setVerbosity
Set the verbosity level. -
getVerbosity
Returns the verbosity level. -
isQuiet
public boolean isQuiet()Check if the verbosity level is set toIO.Verbosity.QUIET. -
isInfo
public boolean isInfo()Check if the verbosity level is set toIO.Verbosity.INFO. -
isVerbose
public boolean isVerbose()Check if the verbosity level is set toIO.Verbosity.VERBOSE. -
isDebug
public boolean isDebug()Check if the verbosity level is set toIO.Verbosity.DEBUG.For general usage, when debug output is required, it is better to use the logging facility instead.
-
flush
public void flush()Flush both output streams. -
close
Close all streams.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-