public class StreamGrabber
extends java.lang.Thread
StreamGrabber asynchronously retrieves the output from an existing input stream in a thread, and stores the output as an ArrayList of Strings. StreamGrabber is useful for retrieving the output from multiple streams simultaneously. For example, StreamGrabber is used by ExecUtils.ExecAndWait to retrieve standard output and standard error from an executed program. You provide the existing input stream and character encoding of the input stream when creating the StreamGrabber.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
encoding
Encoding for input stream.
|
protected java.lang.Exception |
exception
Exception which occurred during grabber execution.
|
protected java.io.InputStream |
inputStream
Input stream to read.
|
protected java.util.List<java.lang.String> |
textLinesList
ArrayList of text lines read from stream.
|
Constructor and Description |
---|
StreamGrabber(java.io.InputStream inputStream)
Create a stream grabber.
|
StreamGrabber(java.io.InputStream inputStream,
java.lang.String encoding)
Create a stream grabber with specified character encoding.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Exception |
getException()
Get stored exception, if any.
|
java.util.List<java.lang.String> |
getGrabbedTextLines()
Get store text lines from the stream.
|
void |
run()
Run the stream grabber thread.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
protected java.io.InputStream inputStream
protected java.lang.String encoding
protected java.util.List<java.lang.String> textLinesList
protected java.lang.Exception exception
public StreamGrabber(java.io.InputStream inputStream)
inputStream
- The stream whose lines
should be retrieved.public StreamGrabber(java.io.InputStream inputStream, java.lang.String encoding)
inputStream
- The stream whose lines
should be retrieved.encoding
- Character encoding for stream.public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public java.lang.Exception getException()
public java.util.List<java.lang.String> getGrabbedTextLines()