Class JsHinter.StreamReaderThread

  • All Implemented Interfaces:
    java.lang.Runnable
    Enclosing class:
    JsHinter

    static class JsHinter.StreamReaderThread
    extends java.lang.Thread
    A thread dedicated to reading either the stdout or stderr stream of an external process. These streams are read in a dedicated thread to ensure they are consumed appropriately to prevent deadlock. This idea was taken from this JavaWorld article.
    • 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 Description
      private java.lang.StringBuilder buffer  
      private java.io.BufferedReader r  
      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      StreamReaderThread​(java.io.InputStream in)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getStreamOutput()
      Returns the output read from the stream.
      void run()
      Continually reads from the output stream until this thread is interrupted.
      • 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
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • r

        private java.io.BufferedReader r
      • buffer

        private java.lang.StringBuilder buffer
    • Constructor Detail

      • StreamReaderThread

        public StreamReaderThread​(java.io.InputStream in)
        Constructor.
        Parameters:
        in - The stream (stdout or stderr) to read from.
    • Method Detail

      • getStreamOutput

        public java.lang.String getStreamOutput()
        Returns the output read from the stream.
        Returns:
        The stream's output, as a String.
      • run

        public void run()
        Continually reads from the output stream until this thread is interrupted.
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread