On Thu, 2011-09-15 at 17:31 +1000, Greg Wilkins wrote:
> Also if we want to do async operations on characters, then NIO.2
> style, that calls back when an operation is complete is better than
> the other style - because we would have to deal with a write(char[])
> coming back and saying it has written 4 chars and 2 bytes of the 5th
> char.
Since you can always write once (if the byte buffer has a reasonable
size), if the decoded char[] fits into the Servlet API byte[] buffer,
then it will always be fine. It is not possible to do a partial write of
the char[], this is still an API with blocking semantics, so the user
has to be reasonable with the array size to avoid blocking.
Essentially, it's the same for write(byte[]) actually, it cannot do any
partial writes, so it has to fit in the Servlet buffer, or non blocking
cannot be guaranteed.
The alternative to work around this is to allow the Servlet buffer to
temporarily scale up to the byte size of the written data, in case it
blocks.
[In my impl, it may block as needed if writing a big byte[] or char[],
which I sort of see as a convenience method]
--
Remy Maucherat <rmaucher_at_redhat.com>
Red Hat Inc