com.kuka.common
Class AsyncStreamReader

java.lang.Object
  extended by java.lang.Thread
      extended by com.kuka.common.AsyncStreamReader
All Implemented Interfaces:
Runnable

public class AsyncStreamReader
extends Thread

Custom stream reader for asynchronous parallel fetching of output and error streams.

In MSDOS, a command is not finished until all stream buffers are completely fetched. A solution is to redirect output streams to self created input streams which write the messages somewhere.

This implementation writes all received chars to a log and to a buffer which can be retrieved calling bufferedStream().

See Also:
NativeCommandExecutor

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AsyncStreamReader(InputStream is, String type)
          Simple stream reader initialized with an input stream and type describing the kind of stream.
 
Method Summary
 String bufferedStream()
          Returns a string containing all lines that have been read from the stream so far.
 void run()
          Start the stream capturing in a separate 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
 

Constructor Detail

AsyncStreamReader

public AsyncStreamReader(InputStream is,
                         String type)
Simple stream reader initialized with an input stream and type describing the kind of stream.

Parameters:
is - the stream to capture. Not allowed to be null.
type - a stream usage indicator for display, e.g. whether the captured stream is an output stream or an error stream. Not allowed to be null.
Method Detail

bufferedStream

public String bufferedStream()
Returns a string containing all lines that have been read from the stream so far.

Returns:
concatenated string of read lines. Never returns null.

run

public void run()
Start the stream capturing in a separate thread.

Specified by:
run in interface Runnable
Overrides:
run in class Thread


Copyright © 2019. All rights reserved.