Class OutputReader

  • All Implemented Interfaces:
    java.lang.Runnable

    public final class OutputReader
    extends java.lang.Thread
    A simple output reader that uses a daemon thread to read from an InputStream and buffer this data. Once end-of-stream is reached, this data will be made available as a String. Note that since the data is buffered in memory, so it is not advisable to use this OutputReader to read large amounts of data.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      OutputReader​(java.io.InputStream source)
      Create an OutputReader that reads from source.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] getResult()
      Returns the data that has been read from the InputStream as a byte array.
      java.lang.String getResultAsString()
      Returns the data that has been read from the InputStream as a String.
      boolean isFinished()
      Returns if the OutputReader has finished (i.e., has reached the end-of-stream on the input).
      void run()
      Entry method for daemon thread.
      void waitUntilFinished()
      Waits until the OutputReader has finished (i.e., has reached the end-of-stream on the input).
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, 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, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • OutputReader

        public OutputReader​(java.io.InputStream source)
        Create an OutputReader that reads from source.
        Parameters:
        source - the {#link InputStream} to read from.
    • Method Detail

      • isFinished

        public boolean isFinished()
        Returns if the OutputReader has finished (i.e., has reached the end-of-stream on the input). If so, the data that has been read is now available through getResultAsString().
        Returns:
        if the OutputReader has finished reading.
      • waitUntilFinished

        public void waitUntilFinished()
        Waits until the OutputReader has finished (i.e., has reached the end-of-stream on the input). After this method returns, the data that has been read is available through getResultAsString().
      • run

        public void run()
        Entry method for daemon thread.
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • getResultAsString

        public java.lang.String getResultAsString()
        Returns the data that has been read from the InputStream as a String. If the OutputReader has not finished reading, this method will block until end-of-stream has been reached.
        Returns:
        the data that has been read.
      • getResult

        public byte[] getResult()
        Returns the data that has been read from the InputStream as a byte array. If the OutputReader has not finished reading, this method will block until end-of-stream has been reached.
        Returns:
        the data that has been read.