Interface LogStream

All Superinterfaces:
AutoCloseable, Closeable, Iterator<LogMessage>
All Known Implementing Classes:
DefaultLogStream

public interface LogStream extends Iterator<LogMessage>, Closeable
  • Method Details

    • readFully

      String readFully()
    • attach

      void attach(OutputStream stdout, OutputStream stderr) throws IOException
      Attaches two OutputStreams to the LogStream. Closes the streams after use.
      Parameters:
      stdout - OutputStream for the standard out
      stderr - OutputStream for the standard err
      Throws:
      IOException - if an I/O error occurs
      See Also:
    • attach

      void attach(OutputStream stdout, OutputStream stderr, boolean closeAtEof) throws IOException
      Attaches two 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&lt;Void&gt;() {
           &#064;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 out
      stderr - OutputStream for the standard err
      closeAtEof - whether to close the streams when this log stream ends
      Throws:
      IOException - if an I/O error occurs
      See Also:
    • close

      void close()
      Redefine to not throw checked exceptions.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable