public abstract class CapturedPrintStream
extends java.io.PrintStream
PrintStream to capture the output to an in-memory or file-backed buffer.
The captured stream is available by calling getReader().
UTF-8 is used for encoding and decoding the stream
content.getInstance(),
getInstance(Path),
getInstance(Path, boolean)| Modifier and Type | Class and Description |
|---|---|
static class |
CapturedPrintStream.FileCapturedPrintStream
A
PrintStream to capture to a file-backed buffer. |
static class |
CapturedPrintStream.MemoryCapturedPrintStream
A
PrintStream to capture to a memory-based buffer. |
| Modifier and Type | Method and Description |
|---|---|
java.io.PrintStream |
append(char c) |
java.io.PrintStream |
append(java.lang.CharSequence csq) |
java.io.PrintStream |
append(java.lang.CharSequence csq,
int start,
int end) |
boolean |
checkError() |
void |
close() |
void |
flush() |
java.io.PrintStream |
format(java.util.Locale l,
java.lang.String format,
java.lang.Object... args) |
java.io.PrintStream |
format(java.lang.String format,
java.lang.Object... args) |
static CapturedPrintStream |
getInstance()
Instantiates a new
CapturedPrintStream using an in-memory buffer. |
static CapturedPrintStream |
getInstance(java.nio.file.Path filePath)
Instantiates a new
CapturedPrintStream using file as a buffer and auto-flush enabled. |
static CapturedPrintStream |
getInstance(java.nio.file.Path filePath,
boolean autoFlush)
Instantiates a new
CapturedPrintStream using file as a buffer and a caller-specified auto-flush setting. |
abstract java.io.BufferedReader |
getReader()
Gets a
BufferedReader over the bytes written to this PrintStream. |
void |
print(boolean b) |
void |
print(char c) |
void |
print(char[] s) |
void |
print(double d) |
void |
print(float f) |
void |
print(int i) |
void |
print(long l) |
void |
print(java.lang.Object obj) |
void |
print(java.lang.String s) |
java.io.PrintStream |
printf(java.util.Locale l,
java.lang.String format,
java.lang.Object... args) |
java.io.PrintStream |
printf(java.lang.String format,
java.lang.Object... args) |
void |
println() |
void |
println(boolean x) |
void |
println(char x) |
void |
println(char[] x) |
void |
println(double x) |
void |
println(float x) |
void |
println(int x) |
void |
println(long x) |
void |
println(java.lang.Object x) |
void |
println(java.lang.String x) |
abstract void |
reset()
Discards the captured output.
|
abstract byte[] |
toByteArray()
Gets a copy of the content of this stream as a byte array.
|
void |
write(byte[] b) |
void |
write(byte[] buf,
int off,
int len) |
void |
write(int b) |
public static CapturedPrintStream getInstance(java.nio.file.Path filePath, boolean autoFlush) throws java.io.IOException
CapturedPrintStream using file as a buffer and a caller-specified auto-flush setting.filePath - Path to file used to capture stream outputautoFlush - true enables auto-flushing of the capture PrintStream;
false disables auto-flushing of the capture PrintStreamCapturedPrintStreamjava.io.IOException - if an error is raised opening an output stream over filePathPrintStream(OutputStream, boolean, String)public static CapturedPrintStream getInstance(java.nio.file.Path filePath) throws java.io.IOException
CapturedPrintStream using file as a buffer and auto-flush enabled.
This method is equivalent to
CapturedPrintStream.getInstance(filePath, true)filePath - Path to file used to capture stream outputCapturedPrintStreamjava.io.IOException - if an error is raised opening an output stream over filePathpublic static CapturedPrintStream getInstance()
CapturedPrintStream using an in-memory buffer.CapturedPrintStreampublic abstract java.io.BufferedReader getReader()
BufferedReader over the bytes written to this PrintStream.
The content of this stream is not altered by this method.BufferedReader over the bytes written to this streamreset()public abstract void reset()
public abstract byte[] toByteArray()
reset()public void flush()
flush in interface java.io.Flushableflush in class java.io.PrintStreampublic void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.PrintStreampublic boolean checkError()
checkError in class java.io.PrintStreampublic void write(int b)
write in class java.io.PrintStreampublic void write(byte[] buf,
int off,
int len)
write in class java.io.PrintStreampublic void print(boolean b)
print in class java.io.PrintStreampublic void print(char c)
print in class java.io.PrintStreampublic void print(int i)
print in class java.io.PrintStreampublic void print(long l)
print in class java.io.PrintStreampublic void print(float f)
print in class java.io.PrintStreampublic void print(double d)
print in class java.io.PrintStreampublic void print(char[] s)
print in class java.io.PrintStreampublic void print(java.lang.String s)
print in class java.io.PrintStreampublic void print(java.lang.Object obj)
print in class java.io.PrintStreampublic void println()
println in class java.io.PrintStreampublic void println(boolean x)
println in class java.io.PrintStreampublic void println(char x)
println in class java.io.PrintStreampublic void println(int x)
println in class java.io.PrintStreampublic void println(long x)
println in class java.io.PrintStreampublic void println(float x)
println in class java.io.PrintStreampublic void println(double x)
println in class java.io.PrintStreampublic void println(char[] x)
println in class java.io.PrintStreampublic void println(java.lang.String x)
println in class java.io.PrintStreampublic void println(java.lang.Object x)
println in class java.io.PrintStreampublic java.io.PrintStream printf(java.lang.String format,
java.lang.Object... args)
printf in class java.io.PrintStreampublic java.io.PrintStream printf(java.util.Locale l,
java.lang.String format,
java.lang.Object... args)
printf in class java.io.PrintStreampublic java.io.PrintStream format(java.lang.String format,
java.lang.Object... args)
format in class java.io.PrintStreampublic java.io.PrintStream format(java.util.Locale l,
java.lang.String format,
java.lang.Object... args)
format in class java.io.PrintStreampublic java.io.PrintStream append(java.lang.CharSequence csq)
append in interface java.lang.Appendableappend in class java.io.PrintStreampublic java.io.PrintStream append(java.lang.CharSequence csq,
int start,
int end)
append in interface java.lang.Appendableappend in class java.io.PrintStreampublic java.io.PrintStream append(char c)
append in interface java.lang.Appendableappend in class java.io.PrintStreampublic void write(byte[] b)
throws java.io.IOException
write in class java.io.FilterOutputStreamjava.io.IOException