Package org.terracotta.utilities.io
Class CapturedPrintStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.PrintStream
-
- org.terracotta.utilities.io.CapturedPrintStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public final class CapturedPrintStream extends java.io.PrintStreamExtendsPrintStreamto capture the output to an in-memory buffer. The captured stream is available by callinggetReader().UTF-8is used for encoding and decoding the stream content.- See Also:
getInstance()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classCapturedPrintStream.LocalBufferedOutputStream
-
Constructor Summary
Constructors Modifier Constructor Description privateCapturedPrintStream()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CapturedPrintStreamgetInstance()Instantiates a newCapturedPrintStream.java.io.BufferedReadergetReader()Gets aBufferedReaderover the bytes written to thisPrintStream.voidreset()Discards the captured output.byte[]toByteArray()Gets a copy of the content of this stream as a byte array.-
Methods inherited from class java.io.PrintStream
append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write
-
-
-
-
Method Detail
-
getInstance
public static CapturedPrintStream getInstance()
Instantiates a newCapturedPrintStream.- Returns:
- a new
CapturedPrintStream
-
getReader
public java.io.BufferedReader getReader()
Gets aBufferedReaderover the bytes written to thisPrintStream. The content of this stream is not altered by this method.- Returns:
- a new
BufferedReaderover the bytes written to this stream - See Also:
reset()
-
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:
reset()
-
-