Strange behaviour of java.nio.charset.StandardCharsets.UTF8.newDecoder()

Pavel Rappo pavel.rappo at oracle.com
Fri Mar 18 19:22:16 UTC 2016


May I ask then how should I tell apart following two cases:

  a. There's a malformed sequence in my bytes and no mater how many bytes I add,
  it will be still malformed
   
  b. Current input is not enough to continue, if more bytes added, the input
  might become well-formed

?

> On 18 Mar 2016, at 18:36, Xueming Shen <xueming.shen at oracle.com> wrote:
> 
> The decoder will NOT keep the "incomplete/leftover" byte(s) internally waiting
> for your new bytes. Those bytes are left in your input ByteBuffer. You need to
> fill the new bytes you have and feed the decoder again.
> 
> 
> On 03/18/2016 11:38 AM, Pavel Rappo wrote:
>> Why is that? I don't think I have to supply only "correct" chunks. After all,
>> decoders are free to maintain an internal state needed for this.
>> 
>>> On 18 Mar 2016, at 18:31, Martin Buchholz<martinrb at google.com>  wrote:
>>> 
>>> trying to decode one byte at a time, which cannot
>>> work?  The minimum unit to decode that will work is 4 bytes
> 



More information about the nio-dev mailing list