T
Tom Anderson
Greets yalls,
Given:
OutputStream out; // this is not buffered
Which is better:
Writer w = new BufferedWriter(new OutputStreamWriter(out));
Writer w = new OutputStreamWriter(new BufferedOutputStream(out));
?
I suppose i'm wondering about (a) whether encoding characters to bytes is
more efficient in bulk than in drips and drabs (and i suppose it must be,
from cache effects alone, but how much so?) and (b) what happens when a
lot of translated characters get written to an unbuffered stream - do the
bytes go in character-by-character (IYSWIM), or in bulk?
The thing that niggles me is that BufferedWriter has a newLine() method,
so i tend to use that for its convenience. But if it's sitting on top of
an OutputStream, then i might need buffering there as well.
I know i could go and read the source code, or do some measurements, and
give me a day or so and i probably will, but this is something i've been
wondering about, so i thought i'd share!
tom
Given:
OutputStream out; // this is not buffered
Which is better:
Writer w = new BufferedWriter(new OutputStreamWriter(out));
Writer w = new OutputStreamWriter(new BufferedOutputStream(out));
?
I suppose i'm wondering about (a) whether encoding characters to bytes is
more efficient in bulk than in drips and drabs (and i suppose it must be,
from cache effects alone, but how much so?) and (b) what happens when a
lot of translated characters get written to an unbuffered stream - do the
bytes go in character-by-character (IYSWIM), or in bulk?
The thing that niggles me is that BufferedWriter has a newLine() method,
so i tend to use that for its convenience. But if it's sitting on top of
an OutputStream, then i might need buffering there as well.
I know i could go and read the source code, or do some measurements, and
give me a day or so and i probably will, but this is something i've been
wondering about, so i thought i'd share!
tom