public class LogStream extends com.google.common.collect.AbstractIterator<LogMessage> implements Closeable
| Modifier and Type | Method and Description |
|---|---|
void |
attach(OutputStream stdout,
OutputStream stderr)
Attaches two
OutputStreams to the LogStream. |
void |
attach(OutputStream stdout,
OutputStream stderr,
boolean closeAtEOF)
Attaches two
OutputStreams to the LogStream. |
void |
close() |
protected LogMessage |
computeNext() |
protected void |
finalize() |
String |
readFully() |
endOfData, hasNext, next, peekclone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemainingprotected void finalize()
throws Throwable
protected LogMessage computeNext()
computeNext in class com.google.common.collect.AbstractIterator<LogMessage>public void close()
close in interface Closeableclose in interface AutoCloseablepublic String readFully()
public void attach(OutputStream stdout, OutputStream stderr) throws IOException
OutputStreams to the LogStream. Closes the streams after
use.stdout - OutputStream for the standard outstderr - OutputStream for the standard errIOException - if an I/O error occursfor control over stream lifecyclespublic void attach(OutputStream stdout, OutputStream stderr, boolean closeAtEOF) throws IOException
OutputStreams to the LogStream.
Example usage:
dockerClient
.attachContainer(containerId,
AttachParameter.LOGS, AttachParameter.STDOUT,
AttachParameter.STDERR, AttachParameter.STREAM)
.attach(System.out, System.err);
Typically you use PipedOutputStream connected to a PipedInputStream which are read by - for example - an InputStreamReader or a Scanner. For small inputs, the PipedOutputStream just writes to the buffer of the PipedInputStream,
but you actually want to read and write from separate threads, as it may deadlock the thread.
final PipedInputStream stdout = new PipedInputStream();
final PipedInputStream stderr = new PipedInputStream();
final PipedOutputStream stdout_pipe = new PipedOutputStream(stdout);
final PipedOutputStream stderr_pipe = new PipedOutputStream(stderr);
executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
dockerClient.attachContainer(containerId,
AttachParameter.LOGS, AttachParameter.STDOUT,
AttachParameter.STDERR, AttachParameter.STREAM
.attach(stdout_pipe, stderr_pipe);
return null;
}
});
try (Scanner sc_stdout = new Scanner(stdout); Scanner sc_stderr = new Scanner(stderr)) {
// ... read here
}
stdout - OutputStream for the standard outstderr - OutputStream for the standard errcloseAtEOF - whether to close the streams when this log stream endsIOException - if an I/O error occursPipedInputStream,
PipedOutputStreamCopyright © 2016. All rights reserved.