Class CapturedPrintStream

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public final class CapturedPrintStream extends PrintStream
Extends PrintStream to capture the output to an in-memory buffer. The captured stream is available by calling getReader(). UTF-8 is used for encoding and decoding the stream content.
See Also:
  • Constructor Details

  • Method Details

    • getInstance

      public static CapturedPrintStream getInstance()
      Instantiates a new CapturedPrintStream.
      Returns:
      a new CapturedPrintStream
    • getReader

      public BufferedReader getReader()
      Gets a BufferedReader over the bytes written to this PrintStream. The content of this stream is not altered by this method.
      Returns:
      a new BufferedReader over the bytes written to this stream
      See Also:
    • reset

      public void reset()
      Discards the captured output.
    • toByteArray

      public byte[] toByteArray()
      Gets a copy of the content of this stream as a byte array. The content of this stream is not altered by this method.
      Returns:
      a byte array containing a copy of the captured data
      See Also: