edu.northwestern.at.utils

## Class StreamGrabber

- java.lang.Object
- - java.lang.Thread
  - - edu.northwestern.at.utils.StreamGrabber

- All Implemented Interfaces:
    java.lang.Runnable

      public class StreamGrabber
      extends java.lang.Thread

  Grabs output from a stream and stores the output in a list of text lines.

  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.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.lang.Thread

      `java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler`

  - ### Field Summary

    Fields
    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.

    - ### Fields inherited from class java.lang.Thread

      `MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

  - ### Constructor Summary

    Constructors
    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.

  - ### Method Summary

    Methods
    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.

    - ### Methods inherited from class java.lang.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`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### inputStream

          protected java.io.InputStream inputStream

      Input stream to read.

    - #### encoding

          protected java.lang.String encoding

      Encoding for input stream. Default is utf-8.

    - #### textLinesList

          protected java.util.List<java.lang.String> textLinesList

      ArrayList of text lines read from stream.

    - #### exception

          protected java.lang.Exception exception

      Exception which occurred during grabber execution. Null if none.

  - ### Constructor Detail

    - #### StreamGrabber

          public StreamGrabber(java.io.InputStream inputStream)

      Create a stream grabber.
      Parameters:
        `inputStream` - The stream whose lines should be retrieved.

    - #### StreamGrabber

          public StreamGrabber(java.io.InputStream inputStream,
                       java.lang.String encoding)

      Create a stream grabber with specified character encoding.
      Parameters:
        `inputStream` - The stream whose lines should be retrieved.
        `encoding` - Character encoding for stream.

  - ### Method Detail

    - #### run

          public void run()

      Run the stream grabber thread.
      Specified by:
        `run` in interface `java.lang.Runnable`
      Overrides:
        `run` in class `java.lang.Thread`

    - #### getException

          public java.lang.Exception getException()

      Get stored exception, if any.
      Returns:
        Stored exception if any occurred during grabber execution.

    - #### getGrabbedTextLines

          public java.util.List<java.lang.String> getGrabbedTextLines()

      Get store text lines from the stream.
      Returns:
        Output text lines stored as an ArrayList of String.