Class CapturePrintStream

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
org.dellroad.querystream.test.io.CapturePrintStream
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class CapturePrintStream extends PrintStream
A PrintStream that can capture what gets printed.
  • Constructor Details

  • Method Details

    • of

      public static CapturePrintStream of(PrintStream out)
      Create an instance.
      Parameters:
      out - underlying output stream
      Returns:
      new stream
      Throws:
      IllegalArgumentException - if out is null
    • startCapture

      public boolean startCapture()
      Start capture.
      Returns:
      true if capture was previously stopped, false if already capturing
    • stopCapture

      public byte[] stopCapture()
      Stop capture and return the captured data.
      Returns:
      captured output if capture was previously started, or null if not capturing
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class PrintStream
    • write

      public void write(int b)
      Overrides:
      write in class PrintStream
    • write

      public void write(byte[] buf, int off, int len)
      Overrides:
      write in class PrintStream