So you can't set this value unless you create your own version of it? So
sun.nio.cs.StreamEncoder buffers at 8192 potentially causing buffer
I'm not sure that's the class defining the buffer. How are you determining
that it is?
overflows at the end of the line?
There should be no risk of buffer overflow.
"The size of this buffer may be specified, but by default it is large enough
for most purposes. "
Specified where exactly?
Sometimes the API docs are not so wonderful. There is no apparent method or
constructor to set the value.
Regardless, you can always get the buffer to flush by calling flush(), so you
don't need to worry about crud being caught in the buffer. Just put a
finally
{
p.flush();
}
in the right place, and you should be fine.
Where the API docs are not so wonderful is in the documentation of these
Writers' buffer strategies, although we've seen that they at least document
that they have them. It makes it hard on us programmers to account for
multiple buffers and the concomitant inefficiencies.
Unless the Writers in question are smart enough to share their buffers? I
don't know - I am far too lazy to read through the publicly available source
code to find out for myself.
I do know that one can at least make sure, as you've done, that there are at
least some buffers. Your BufferedWriter of size 4096 will hold 8192 bytes in
its buffer, apparently a good match for the default (and ineluctable)
OutputStreamWriter buffer. Finish with a flush() and all should be well.