The whole double buffering thing isn't quite what you might expect...
At
http://github.com/cemerick/clojure-contrib.git, we find:
>
> commit 3f299db2a509bd235b4125c14b2a6f67f855eb50
> Author: Chas Emerick <
ceme...@snowtide.com>
> Date: 2010-04-26 09:13:15 -0400
>
[... snip ...]
> - added *buffer-streams* var in order to prevent redundant
> buffering, and to allow users to get unbuffered streams if they
> really want to
[... snip ...]
> (def #^{:doc "When true, all Streams protocol method implementations should return
> buffered varieties of their respective return types (e.g.
> a BufferedWriter instead of an OutputStreamWriter), by either
> doing so directly or recursively calling back into the same
> Streams protocol method in order to dispatch to an implementation
> that exists solely for this purpose.
>
> Defaults to true. This primarily exists so as to avoid double-
> buffering at both the byte and character levels, though it can
> be bound in application code if you are really sure you don't want
> IO buffering for some reason."}
> *buffer-streams* true)
I did something similar back in november when I was adding
input-stream and friends to
c.c.io (then duck-streams), but soon
discovered that the whole double buffering thing wasn't all it's
cracked up to be:
commit 6926aa526a5135c1ff31418d8b881db1997a142f
Author: Ben Smith-Mannschott <
bsmit...@gmail.com>
Date: 2009-12-20 10:24:31 +0100
fix: no longer assume that it's best to only buffer once
Happily buffer at both the Character and Byte levels
----------------------------------------------------
Previously, we went to pains to buffer only once, reasoning that
buffering at both the InputStream and Reader levels when opening a
Reader is wasteful and that it's best to buffer at the top of the
stack (i.e. a BufferedReader on a plain InputStream). However, this
design choice may be based on an incorrect assumption:
We use a BufferedInputStream with a 128k buffer to increase the
number of bytes we’re reading from the disk at a time. The reason
we can’t just give the BufferedReader a large buffer is that
InputStreamReader reads in 8192 byte blocks so we really need that
buffer at the byte level.
http://meshy.org/2009/12/13/widefinder-2-with-clojure.html
Reading the source of InputStreamReader confirms
this. InputStreamReader uses a NIO StreamDecoder to do the actual byte
to character translation and this StreamDecoder is always created with
DEFAULT_BYTE_BUFFER_SIZE of 8192.
// Ben