public class WriterOutputStream extends OutputStream
WriterOutputStream is a bridge from byte streams to character
streams: bytes written to it are decoded into characters using a specified
charset. The charset that it uses may be specified by
name or given explicitly, or the system default charset may be used. The
decoded characters are written to a provided Appendable, which will
usually be a Writer.
The input is buffered so that writes don't need to be aligned to character boundaries. Because conversion is only performed when the input buffer is full (or when the stream is flushed) output also behaves as if it were buffered. It is therefore usually unnecessary to externally buffer the input or output.
In some charsets some or all characters are represented by multi-byte
sequences. If a byte sequence is encountered that is not valid in the input
charset or that cannot be mapped to a valid Unicode character it will be
replaced in the output with the value "�". If more control
over the decoding process is required use CharsetDecoder.
InputStreamReader,
OutputStreamWriter| Constructor and Description |
|---|
WriterOutputStream(Appendable target)
Creates a
WriterOutputStream with the default charset. |
WriterOutputStream(Appendable target,
Charset charset)
Creates a
WriterOutputStream with the given charset. |
WriterOutputStream(Appendable target,
String charset)
Creates a
WriterOutputStream with the named charset. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the stream, flushing it first.
|
void |
flush()
Flushes the input buffer through the decoder.
|
void |
write(byte[] buffer,
int offset,
int length) |
void |
write(int b) |
writepublic WriterOutputStream(Appendable target)
WriterOutputStream with the default charset.target - the sink for the decoded characterspublic WriterOutputStream(Appendable target, String charset)
WriterOutputStream with the named charset.target - the sink for the decoded characterscharset - the character set with which to interpret the input bytespublic WriterOutputStream(Appendable target, Charset charset)
WriterOutputStream with the given charset.target - the sink for the decoded characterscharset - the character set with which to interpret the input bytespublic void write(byte[] buffer,
int offset,
int length)
throws IOException
write in class OutputStreamIOExceptionpublic void write(int b)
throws IOException
write in class OutputStreamIOExceptionpublic void flush()
throws IOException
Writer its
flush method will be called after all buffered input has
been flushed.flush in interface Flushableflush in class OutputStreamIOExceptionpublic void close()
throws IOException
Writer its close method will be called after all
buffered input has been flushed. Once the stream has been closed further
calls to write or flush will cause an
IOException to be thrown. Closing a previously closed
stream has no effect.close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOExceptionCopyright © 2002–2019 Starter Inc.. All rights reserved.