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.OutputStream
An 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
OutputStream
to aWriter
for compatibility purposes. It is much more efficient to write to theWriter
directly.
-
-
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 void
close()
void
flush()
void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
-
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
-