Re: Charsets for hex/base64

2018-05-03 Thread David Lloyd
I feel like what you're looking for is really a general-purpose data transformation API. I think bending charsets into this shape would be a bad move, but I like the idea of a more generalized solution. Google Guava has such an abstraction, and I know of a couple of others a well. On Thu, May 3,

Re: Charsets for hex/base64

2018-05-03 Thread Jonas Konrad
Well technically there is some sort of precedent to this, since CharsetEncoder/Decoder operate on CharBuffers which are just utf-16 encoded strings. So charsets already may produce a single output code *unit* for multiple input code units (UTF-32, which may output 1 code unit for 2 UTF-16 input

Re: Charsets for hex/base64

2018-05-02 Thread Vincent Ryan
FYI here’s the javadoc for a draft of the Hex API that Alan mentioned below: http://cr.openjdk.java.net/~vinnie/8170769/javadoc.05/api/java.base/java/util/Hex.html Thanks. > On 2 May 2018, at 10:55, Jonas Konrad wrote: > > I did not know about the old HexDumpEncoder. It extends an internal cla

Re: Charsets for hex/base64

2018-05-02 Thread Weijun Wang
> On May 2, 2018, at 4:35 PM, Jonas Konrad wrote: > > "0a0b0c".getBytes(HexCharset.getInstance()) = new byte[] { 0x0a, 0x0b, 0x0c } > new String(new byte[] { 0x0a, 0x0b, 0x0c }, HexCharset.getInstance()) = > "0a0b0c" Normally a charset is to encode a string to byte[], but here you can actuall

Re: Charsets for hex/base64

2018-05-02 Thread Jonas Konrad
I did not know about the old HexDumpEncoder. It extends an internal class `CharacterEncoder` which seems to be pretty similar purpose-wise to what I am suggesting with CharsetEncoder. There is also the good old `DatatypeConverter.printHexBinary`, though it can't stream. But this is not really

Re: Charsets for hex/base64

2018-05-02 Thread Alan Bateman
On 02/05/2018 09:35, Jonas Konrad wrote: Hi, Conceptually, a 'charset' (in java) is a pair of transformations from bytes to utf-16 code units and vice versa. Could it be useful to have charset implementations that convert from bytes to the hex (or base64) representations of those? The idea is

Charsets for hex/base64

2018-05-02 Thread Jonas Konrad
Hi, Conceptually, a 'charset' (in java) is a pair of transformations from bytes to utf-16 code units and vice versa. Could it be useful to have charset implementations that convert from bytes to the hex (or base64) representations of those? The idea is as follows: "0a0b0c".getBytes(HexCharse