RFR: JDK-8021560,(str) String constructors that take ByteBuffer

Robert Muir rcmuir at gmail.com
Sat Feb 17 13:45:45 UTC 2018

On Sat, Feb 17, 2018 at 4:05 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:

> Just to add that the existing low-level / advanced API for this is
> CharsetEncoder. The CoderResult from an encode and the buffer positions
> means you know when there is overflow, the number of characters encoded, and
> how many bytes were added to the buffer. It also gives fine control on how
> encoding errors should be handled and you cache a CharsetEncoder to avoid
> some of the performance anomalies that come up in the Charset vs. charset
> name discussions.

> This is not an API that most developers will ever use
> directly but if the use-case is advanced cases (libraries or frameworks

Really? How else are you supposed to convert bytes <-> characters
reliably in java without using CharsetEncoder/Decoder? Its the only
way to get an exception when something is wrong, instead of silently
masking errors with replacement characters (the JDK seems to think its
doing people favors there, its not).

More information about the core-libs-dev mailing list