Class TeeWriter
java.lang.Object
java.io.Writer
io.github.ascopes.jct.diagnostics.TeeWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
A writer that wraps an output stream and also writes any content to an in-memory buffer.
This is thread-safe.
- Since:
- 0.0.1
- Author:
- Ashley Scopes
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
flush()
Get the content of the internal buffer.toString()
Get the content of the internal buffer.static TeeWriter
wrapOutputStream
(OutputStream outputStream, Charset charset) Create a tee writer for the given output stream.void
write
(char[] buffer, int offset, int length)
-
Constructor Details
-
TeeWriter
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
-
getContent
Get the content of the internal buffer.- Returns:
- the content.
- Since:
- 0.2.1
-
toString
-
write
- Specified by:
write
in classWriter
- Throws:
IOException
-
wrapOutputStream
Create a tee writer for the given output stream.Remember you may need to manually flush the tee writer for all contents to be committed to the output stream.
- Parameters:
outputStream
- the output stream.charset
- the charset.- Returns:
- the Tee Writer.
- Since:
- 0.2.1
-