Feature suggestion: Add support to Base64.Encoder and Base64.Decoder to wrap Writer / Reader
openjdk at icemanx.nl
Tue Jan 8 21:08:59 UTC 2019
Java 8 added Base64 with its nested classes Encoder and Decoder. These
both have methods to wrap an OutputStream / InputStream respectively.
However, base64 is text; the alphabets exist out of ASCII characters
only. This is (somewhat) acknowledged by the presence of the
encodeToString(byte) and decode(String) methods. Doesn't it then also
make sense to add methods to wrap a Writer and Reader respectively?
(Perhaps Appendable / Readable is even better to provide more
flexibility.) When reading an exception can be thrown if an unsupported
character is encountered.
I have already written a simple example to wrap a StringBuilder in an
OutputStream that I then wrap using Base64.Encoder:
This could probably add some validation that characters are limited to
the actual alphabet in the convert method, but I was a bit lazy there.
If an Appendable is wrapped the flush and close methods should delegate
to the wrapped object if that implements Flushable / Closeable respectively.
More information about the core-libs-dev