Package org.moeaframework.util.io
Class RedirectStream
java.lang.Object
java.lang.Thread
org.moeaframework.util.io.RedirectStream
- All Implemented Interfaces:
Runnable
Redirects all content received by an
InputStream to an OutputStream. This thread terminates when
the input stream is closed or the end of file is reached. The output stream is never closed.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcapture(ProcessBuilder processBuilder) Invokes the process and captures the output.static voidinvoke(ProcessBuilder processBuilder) Invokes the process and pipes output and error messages toSystem.outandSystem.err, respectively.static voidpipe(ProcessBuilder processBuilder, OutputStream out) Invokes the process and pipes output to the given stream.static voidpipe(ProcessBuilder processBuilder, OutputStream out, OutputStream err) Invokes the process and pipes output and error messages to the given streams.static RedirectStreamredirect(InputStream inputStream) Reads all the contents of the specified input stream.static RedirectStreamredirect(InputStream inputStream, OutputStream outputStream) Redirects all the contents from the specified input stream to the specified output stream.voidrun()Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Method Details
-
run
public void run() -
redirect
Reads all the contents of the specified input stream. The contents are immediately deleted and are not redirected anywhere.- Parameters:
inputStream- the input stream from which content is read- Returns:
- the thread, which can be joined to await termination
-
redirect
Redirects all the contents from the specified input stream to the specified output stream.- Parameters:
inputStream- the input stream from which content is readoutputStream- the output stream to which the content is redirected- Returns:
- the thread, which can be joined to await termination
-
capture
public static String capture(ProcessBuilder processBuilder) throws IOException, InterruptedException Invokes the process and captures the output. Any error messages are sent toSystem.err.- Parameters:
processBuilder- the process builder- Returns:
- the captured output
- Throws:
IOException- if an I/O error occurred while running the processInterruptedException- if this thread was interrupted while waiting for the process to terminate
-
pipe
public static void pipe(ProcessBuilder processBuilder, OutputStream out) throws IOException, InterruptedException Invokes the process and pipes output to the given stream. Any error messages are sent toSystem.err.- Parameters:
processBuilder- the process builderout- the stream where output is piped- Throws:
IOException- if an I/O error occurred while running the processInterruptedException- if this thread was interrupted while waiting for the process to terminate
-
pipe
public static void pipe(ProcessBuilder processBuilder, OutputStream out, OutputStream err) throws IOException, InterruptedException Invokes the process and pipes output and error messages to the given streams.- Parameters:
processBuilder- the process builderout- the stream where output is pipederr- the stream where error messages are piped- Throws:
IOException- if an I/O error occurred while running the processInterruptedException- if this thread was interrupted while waiting for the process to terminate
-
invoke
Invokes the process and pipes output and error messages toSystem.outandSystem.err, respectively.- Parameters:
processBuilder- the process builder- Throws:
IOException- if an I/O error occurred while running the processInterruptedException- if this thread was interrupted while waiting for the process to terminate
-