Package nl.esciencecenter.xenon.utils
Class OutputReader
- java.lang.Object
-
- java.lang.Thread
-
- nl.esciencecenter.xenon.utils.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 anInputStream
and buffer this data. Once end-of-stream is reached, this data will be made available as aString
. Note that since the data is buffered in memory, so it is not advisable to use this OutputReader to read large amounts of data.
-
-
Constructor Summary
Constructors Constructor Description OutputReader(java.io.InputStream source)
Create an OutputReader that reads fromsource
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
getResult()
Returns the data that has been read from theInputStream
as a byte array.java.lang.String
getResultAsString()
Returns the data that has been read from theInputStream
as aString
.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
-
-
-
-
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 throughgetResultAsString()
.- 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 throughgetResultAsString()
.
-
run
public void run()
Entry method for daemon thread.- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
getResultAsString
public java.lang.String getResultAsString()
Returns the data that has been read from theInputStream
as aString
. 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 theInputStream
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.
-
-