On Feb 12, 2009, at 3:39 PM, Phil Hagelberg wrote:
I'm no Java IO expert, but it sounds like a BufferedReader is the right thing in the majority of cases. I think having "read" wrap its stream ina PushbackReader where necessary is a much better, non-intrusive solution, and my implementation seems to work fine.
I don't think wrapping readers within read can work properly in all cases. The problem is that the PushbackReader created within read may end its life with a character still in its pushback buffer. If that happens, subsequent clients of the wrapped reader should logically receive that lost character first, but will instead receive the one after it.
This problem wouldn't be immediately apparent in testing because frequently that lost character would be whitespace. Losing it wouldn't have a high-level effect.
Here's an example of where wrapping within read fails:Before the patch is applied. read requires a PushbackReader, so I wrap my reader in one and then read the two objects from the string.
user=> (def a (java.io.PushbackReader. (java.io.StringReader. "123[145]")))
#'user/a user=> (read a) 123 user=> (read a) [145] The two objects are read correctly. Now I apply the patch and use the convenience it offers: user=> (def a (java.io.StringReader. "123[145]")) #'user/a user=> (read a) 123 user=> (read a) 145The "[" on the input stream was lost so the second object is read as a number rather than a vector.
--Steve
smime.p7s
Description: S/MIME cryptographic signature