Package org.jline.utils
Class WriterOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.jline.utils.WriterOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class WriterOutputStream extends java.io.OutputStreamAn OutputStream implementation that writes to a Writer, bridging byte and character streams.The WriterOutputStream class provides an OutputStream implementation that redirects its output to a Writer by decoding the bytes using a specified character encoding. This allows code that expects to write to an OutputStream to work with a Writer destination instead.
This class handles the complexities of character encoding conversion, including:
- Proper handling of multi-byte character encodings
- Buffering of partial character sequences
- Configurable behavior for malformed input and unmappable characters
This class is particularly useful in JLine for bridging between byte-oriented and character-oriented I/O in terminal handling, especially when dealing with legacy APIs that expect byte streams.
Note: This class should only be used if it is necessary to redirect an
OutputStreamto aWriterfor compatibility purposes. It is much more efficient to write to theWriterdirectly.
-
-
Constructor Summary
Constructors Constructor Description WriterOutputStream(java.io.Writer out, java.nio.charset.Charset charset)WriterOutputStream(java.io.Writer out, java.nio.charset.CharsetDecoder decoder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)
-
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
-