public class DumpStreamThread extends Thread
InputStream and writing everything to an OutputStream.
While this functionality is useful for multiple purposes, we use DumpStreamThread primarily for
child processes. When starting another process (e.g. via the
ProcessBuilder), it is necessary to read the process' output. Without
doing this, the child process might block forever - especially on Windows (having a very limited
standard-output-buffer), this is a well-known problem.
Since the main thread (invoking the child process) usually blocks and waits for the child process to return (i.e. exit), dumping its standard-out and standard-error to a buffer or a log file is done on a separate thread.
Please note that DumpStreamThread can automatically write everything to the log. This is done via
an instance of LogDumpedStreamThread.
Thread.State, Thread.UncaughtExceptionHandlerMAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
DumpStreamThread(InputStream inputStream,
OutputStream outputStream,
org.slf4j.Logger childProcessLogger)
Creates an instance of
DumpStreamThread. |
DumpStreamThread(InputStream inputStream,
OutputStream outputStream,
String childProcessLoggerName)
Creates an instance of
DumpStreamThread. |
| Modifier and Type | Method and Description |
|---|---|
void |
flushBuffer() |
StringBuffer |
getOutputStringBuffer() |
int |
getOutputStringBufferMaxLength() |
void |
interrupt() |
boolean |
isInterrupted() |
void |
run() |
void |
setIgnoreErrors(boolean ignoreErrors) |
void |
setOutputStringBuffer(StringBuffer outputStringBuffer)
Sets a
StringBuffer for capturing all output. |
void |
setOutputStringBufferMaxLength(int outputStringBufferMaxLength) |
void |
start() |
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yieldpublic DumpStreamThread(InputStream inputStream, OutputStream outputStream, String childProcessLoggerName)
DumpStreamThread.inputStream - the stream to read from. Must not be null.outputStream - the stream to write to. Must not be null.childProcessLoggerName - the name of the logger. May be null if logging is not
desired. In case of null, logging is completely disabled.public DumpStreamThread(InputStream inputStream, OutputStream outputStream, org.slf4j.Logger childProcessLogger)
DumpStreamThread.inputStream - the stream to read from. Must not be null.outputStream - the stream to write to. Must not be null.childProcessLogger - the logger. May be null if logging is not desired.public void setIgnoreErrors(boolean ignoreErrors)
public boolean isInterrupted()
isInterrupted in class Threadpublic void setOutputStringBuffer(StringBuffer outputStringBuffer)
StringBuffer for capturing all output.
Please note, that only data read from the stream after this was set is captured. You normally want to
set this StringBuffer.
This feature is only available, if logging is enabled.
outputStringBuffer - the StringBuffer used for capturing. May be null.public StringBuffer getOutputStringBuffer()
public void setOutputStringBufferMaxLength(int outputStringBufferMaxLength)
public int getOutputStringBufferMaxLength()
public void flushBuffer()
Copyright © 2013–2017. All rights reserved.