What to do about write(CharBuffer)?

2 messages Options
Embed this post
Permalink
Gili

What to do about write(CharBuffer)?

Reply Threaded More More options
Print post
Permalink
Hi,

As discussed before, I've got a class that reads/writes CharBuffers on top of an existing AsynchronousByteChannel. I'd like your opinion on the following problem.

When a user writes out a CharBuffer, I use CharsetEncoder.encode() to convert it to bytes. The value of CharsetEncoder.encode()'s "endOfInput" argument is used to trigger malformed-character errors. It's not clear how I'm supposed to know whether I've reach the end of input...

So, does that imply I should change the method signature from write(CharBuffer) to write(CharBuffer, endOfInput)?

Thanks,
Gili
Martin Buchholz

Re: What to do about write(CharBuffer)?

Reply Threaded More More options
Print post
Permalink
In the general case, an encoder needs to know whether there is
more input, not just for error detection, but also for
producing the correct output.
If some encoder produced different output for
x
and
x + UMLAUT
then if the last char is 'x' we need some more input
or we need to know that there will be no more.

Again in the general case the encoder will need to
maintain state between encodes of CharBuffers, and the behavior
may be different on the final one.

Martin


On Sun, Jun 28, 2009 at 15:13, Gili <[hidden email]> wrote:

Hi,

As discussed before, I've got a class that reads/writes CharBuffers on top
of an existing AsynchronousByteChannel. I'd like your opinion on the
following problem.

When a user writes out a CharBuffer, I use CharsetEncoder.encode() to
convert it to bytes. The value of CharsetEncoder.encode()'s "endOfInput"
argument is used to trigger malformed-character errors. It's not clear how
I'm supposed to know whether I've reach the end of input...

So, does that imply I should change the method signature from
write(CharBuffer) to write(CharBuffer, endOfInput)?

Thanks,
Gili
--
View this message in context: http://n2.nabble.com/What-to-do-about-write%28CharBuffer%29--tp3171370p3171370.html
Sent from the nio-discuss mailing list archive at Nabble.com.