public final class AsciiOutputStream extends OutputStream
AsciiOutputStream
, it will thrown an IOException
.
This can be used in code that expects an output stream where a writer is available.
One such example is base64 encoding. Even though base64 is text, Base64.Encoder
can only wrap OutputStream
. This method can help:
OutputStream output = Base64.getEncoder().wrap(new AsciiOutputStream(writer));
When an AsciiOutputStream
is closed, the wrapped writer will be closed as well.
Constructor and Description |
---|
AsciiOutputStream(Writer output)
Creates a new ASCII output stream.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
write
public AsciiOutputStream(Writer output)
output
- The writer to wrap.NullPointerException
- If the given writer is null
.public void write(int b) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class OutputStream
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
Copyright © 2020–2024. All rights reserved.