Package com.spotify.docker.client
Interface LogStream
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
,java.util.Iterator<LogMessage>
- All Known Implementing Classes:
DefaultLogStream
public interface LogStream extends java.util.Iterator<LogMessage>, java.io.Closeable
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
attach(java.io.OutputStream stdout, java.io.OutputStream stderr)
Attaches twoOutputStream
s to theLogStream
.void
attach(java.io.OutputStream stdout, java.io.OutputStream stderr, boolean closeAtEof)
Attaches twoOutputStream
s to theLogStream
.void
close()
Redefine to not throw checked exceptions.java.lang.String
readFully()
-
-
-
Method Detail
-
readFully
java.lang.String readFully()
-
attach
void attach(java.io.OutputStream stdout, java.io.OutputStream stderr) throws java.io.IOException
Attaches twoOutputStream
s to theLogStream
. Closes the streams after use.- Parameters:
stdout
- OutputStream for the standard outstderr
- OutputStream for the standard err- Throws:
java.io.IOException
- if an I/O error occurs- See Also:
for control over stream lifecycles
-
attach
void attach(java.io.OutputStream stdout, java.io.OutputStream stderr, boolean closeAtEof) throws java.io.IOException
Attaches twoOutputStream
s to theLogStream
.Example usage:
dockerClient .attachContainer(containerId, AttachParameter.LOGS, AttachParameter.STDOUT, AttachParameter.STDERR, AttachParameter.STREAM) .attach(System.out, System.err);
Typically you use
PipedOutputStream
connected to aPipedInputStream
which are read by - for example - anInputStreamReader
or aScanner
. For small inputs, thePipedOutputStream
just writes to the buffer of thePipedInputStream
, 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 }
- Parameters:
stdout
- OutputStream for the standard outstderr
- OutputStream for the standard errcloseAtEof
- whether to close the streams when this log stream ends- Throws:
java.io.IOException
- if an I/O error occurs- See Also:
PipedInputStream
,PipedOutputStream
-
close
void close()
Redefine to not throw checked exceptions.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
-