Class StreamDrainer
java.lang.Object
ubic.gemma.core.util.StreamDrainer
Reads a stream to its end on a daemon thread, keeping the last
maxChars characters.
Use it for a child process's standard error when the parent waits for the process, or reads its standard output, before reading standard error. A child blocks once it has written a pipe buffer's worth (64 KiB on Linux) that nobody reads, so without this such a child and the parent wait on each other forever.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intEnough for an error message and its context; the start of a long output is dropped. -
Method Summary
Modifier and TypeMethodDescriptionWait up to the given time for the end of the stream, then return what was kept.getText()static StreamDrainerstart(InputStream stream, String name) Start reading the stream on a new daemon thread, keeping the lastDEFAULT_MAX_CHARScharacters.static StreamDrainerstart(InputStream stream, String name, int maxChars)
-
Field Details
-
DEFAULT_MAX_CHARS
public static final int DEFAULT_MAX_CHARSEnough for an error message and its context; the start of a long output is dropped.- See Also:
-
-
Method Details
-
start
Start reading the stream on a new daemon thread, keeping the lastDEFAULT_MAX_CHARScharacters.- Parameters:
name- for the thread, e.g."RepeatMasker stderr"
-
start
-
await
Wait up to the given time for the end of the stream, then return what was kept.The end of a process's stream normally follows its exit closely, but a descendant that inherited the stream can hold it open, hence the timeout.
- Throws:
InterruptedException
-
getText
- Returns:
- what has been kept so far
-