Classes | |
class | GobblerRunnable |
Public Member Functions | |
ProcessStreamGobbler (Process proc, ThreadFactory tf, boolean storeStreamContent) | |
void | gobbleAsync () throws InterruptedException |
boolean | gobble (long timeout, TimeUnit unit) throws InterruptedException |
List< String > | getStdout () |
List< String > | getStderr () |
boolean | hasStreamReadErrors () |
boolean | hasTerminated () |
void | setDebug (boolean DEBUG) |
Continuously reads the stdout and stderr streams of Process in separate threads, so that the OS will not block out the JVM, as it could otherwise happen if lines are read from these streams sequentially in one thread.
This class is only useful if the external process's output is either not interesting at all for the user, or if the output should be read only after the process has terminated. Otherwise the streams should be read directly without using this class.
The gobble(long, TimeUnit) call returns either when both stdout and stderr streams deliver a null, or if the timeout is reached. check if relying on the null from both streams is as robust as Process#waitFor().
alma.acs.util.ProcessStreamGobbler.ProcessStreamGobbler | ( | Process | proc, | |
ThreadFactory | tf, | |||
boolean | storeStreamContent | |||
) |
proc | The process whose streams we want to read. | |
tf | ThreadFactory to be used to create the two threads that read the stdout and stderr streams | |
storeStreamContent | If true, then the stdout and stderr content will be stored and can be read using getStdout() and getStderr() : set max sizes for the buffers |
List<String> alma.acs.util.ProcessStreamGobbler.getStderr | ( | ) |
Returns the stderr data read, or null if storeStreamContent==false
List<String> alma.acs.util.ProcessStreamGobbler.getStdout | ( | ) |
Returns the stdout data read, or null if storeStreamContent==false
Referenced by alma.acs.testsupport.ProcessUtil.getJavaPIDs().
boolean alma.acs.util.ProcessStreamGobbler.gobble | ( | long | timeout, | |
TimeUnit | unit | |||
) | throws InterruptedException |
Starts fetching process output from stdout/stderr, storing it internally so that it can later be read via getStdout() and getStderr().
Use this method if you want to wait for the process to end, limited by a timeout.
: set max sizes for the buffers
timeout | maximum time to wait for the process to finish | |
unit | unit for the timeout |
true
if returning because the process ended, otherwise false
if the timeout applied (in which case the streams will continue to be read though). InterruptedException |
Referenced by alma.acs.testsupport.ProcessUtil.getJavaPIDs(), and alma.acs.util.ProcessStreamGobbler.gobbleAsync().
void alma.acs.util.ProcessStreamGobbler.gobbleAsync | ( | ) | throws InterruptedException |
Starts fetching process output from stdout/stderr, storing it internally so that it can later be read via getStdout() and getStderr().
Use this method if you do not want to wait for the process to end. The status can anyway be checked using hasTerminated().
timeout | maximum time to wait for the process to finish | |
unit | unit for the timeout |
true
if returning because the process ended, otherwise false
if the timeout applied (in which case the streams will continue to be read though). InterruptedException |
References alma.acs.util.ProcessStreamGobbler.gobble().
boolean alma.acs.util.ProcessStreamGobbler.hasStreamReadErrors | ( | ) |
IllegalStateException | if called before gobble(long, TimeUnit) or gobbleAsync(). |
Referenced by alma.acs.testsupport.ProcessUtil.getJavaPIDs().
boolean alma.acs.util.ProcessStreamGobbler.hasTerminated | ( | ) |
void alma.acs.util.ProcessStreamGobbler.setDebug | ( | boolean | DEBUG | ) |
Referenced by alma.acs.testsupport.ProcessUtil.getJavaPIDs().