Package aQute.lib.redirect
Class Redirect
- java.lang.Object
-
- aQute.lib.redirect.Redirect
-
public class Redirect extends java.lang.Object
Utility to redirect the stdin/stdout/stderr when running a command
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
captureStderr
private boolean
captureStdout
private Capture
cstderr
private Capture
cstdout
private java.io.OutputStream
stderr
private java.io.InputStream
stdin
private java.io.OutputStream
stdout
-
Constructor Summary
Constructors Constructor Description Redirect(java.io.InputStream stdin, java.io.OutputStream stdout, java.io.OutputStream stderr)
Create a stdio redirectorRedirect(java.io.OutputStream stdout, java.io.OutputStream stderr)
Create a stdio redirector without any inputRedirect(java.lang.String stdin, java.io.OutputStream stdout, java.io.OutputStream stderr)
Create a stdio redirector
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <R> R
apply(SupplierWithException<R> f)
Call the supplier and return the result.private java.io.PrintStream
build(java.io.PrintStream original, java.io.OutputStream redirect, Capture capture)
Redirect
captureStderr()
Capture stderr during an apply.Redirect
captureStdout()
Capture stdout during an apply.java.lang.String
getContent()
java.lang.String
getStderr()
java.lang.String
getStdout()
-
-
-
Field Detail
-
stdin
private final java.io.InputStream stdin
-
stdout
private final java.io.OutputStream stdout
-
stderr
private final java.io.OutputStream stderr
-
captureStdout
private boolean captureStdout
-
captureStderr
private boolean captureStderr
-
cstdout
private Capture cstdout
-
cstderr
private Capture cstderr
-
-
Constructor Detail
-
Redirect
public Redirect(java.io.InputStream stdin, java.io.OutputStream stdout, java.io.OutputStream stderr)
Create a stdio redirector- Parameters:
stdin
- the stdin read from or null for System.instdout
- the stdout to write to or null for System.outstderr
- the stderr to write to or null for System.err
-
Redirect
public Redirect(java.lang.String stdin, java.io.OutputStream stdout, java.io.OutputStream stderr)
Create a stdio redirector- Parameters:
stdin
- the stdin read from or null for System.instdout
- the stdout to write to or null for System.outstderr
- the stderr to write to or null for System.err
-
Redirect
public Redirect(java.io.OutputStream stdout, java.io.OutputStream stderr)
Create a stdio redirector without any input- Parameters:
stdout
- the stdout to write to or null for System.outstderr
- the stderr to write to or null for System.err
-
-
Method Detail
-
captureStdout
public Redirect captureStdout()
Capture stdout during an apply. Every apply will be captured seperately.- Returns:
- this
-
captureStderr
public Redirect captureStderr()
Capture stderr during an apply. Every apply will be captured seperately.- Returns:
- this
-
apply
public <R> R apply(SupplierWithException<R> f) throws java.lang.Exception
Call the supplier and return the result. While the supplier is active, the System streams are redirected as instructed by the constructor. Redirection & capture will only take place on the current thread. The original state will be introduced afterwards.Although the system streams are redirected, the original output streams are still written to.
- Type Parameters:
R
- the type for the supplier- Parameters:
f
- the supplier- Returns:
- the return of the supplier.
- Throws:
java.lang.Exception
-
build
private java.io.PrintStream build(java.io.PrintStream original, java.io.OutputStream redirect, Capture capture)
-
getStderr
public java.lang.String getStderr()
-
getStdout
public java.lang.String getStdout()
-
getContent
public java.lang.String getContent()
-
-