public static final class CapturedPrintStream.FileCapturedPrintStream extends CapturedPrintStream
PrintStream to capture to a file-backed buffer.
The captured stream is available by calling getReader().
UTF-8 is used for encoding and decoding the stream content.CapturedPrintStream.getInstance(Path)CapturedPrintStream.FileCapturedPrintStream, CapturedPrintStream.MemoryCapturedPrintStream| Modifier and Type | Method and Description |
|---|---|
java.io.BufferedReader |
getReader()
Gets a
BufferedReader over the bytes written to this PrintStream. |
void |
reset()
Discards the captured output.
|
void |
sync()
Ensures all buffered content is flushed to disk.
|
byte[] |
toByteArray()
Gets a copy of the content of this stream as a byte array.
|
append, append, append, checkError, close, flush, format, format, getInstance, getInstance, getInstance, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, write, write, writepublic void sync()
throws java.io.IOException
java.io.IOException - if an error is raised from the FileDescriptor.sync() callpublic java.io.BufferedReader getReader()
BufferedReader over the bytes written to this PrintStream.
The content of this stream is not altered by this method.
This method calls CapturedPrintStream.flush() and FileDescriptor.sync() to ensure all captured
output is available to the reader.
getReader in class CapturedPrintStreamBufferedReader over the bytes written to this streamjava.io.UncheckedIOException - for a CapturedPrintStream.FileCapturedPrintStream if an IOException is
thrown when opening the file for readingCapturedPrintStream.reset()public void reset()
This method closes the previous PrintStream delegate iff the new delegate is successfully created.
reset in class CapturedPrintStreamjava.io.UncheckedIOException - if an error is raised while opening the new delegatepublic byte[] toByteArray()
This method calls CapturedPrintStream.flush() and FileDescriptor.sync() to ensure all captured
output is available to the reader.
toByteArray in class CapturedPrintStreamjava.io.UncheckedIOException - if an error is raised while reading the backing fileCapturedPrintStream.reset()