[jdom-interest] StringReader versus StringBufferInputStream
Jason Hunter
jhunter at xquery.com
Mon Aug 30 13:25:47 PDT 2004
>>The SAXBuilder.build() javadocs say this about using
>>a StringReader (Reader
>>actually): "It's always safer to use an InputStream
>>rather than a Reader,
>>if it's available."
>
> This seems wrong. I think what it should say is "if
> you have a stream and are not sure about its encoding,
> it's safer to pass stream instead of trying to create
> a reader". This because XML parsers in general can
> auto-detect encoding from initial stream bytes, and/or
> from xml declaration (if one exists), and then
> construct appropriate reader that uses proper decoder.
> But properly constructed Readers are as safe as it
> gets, that statement just seems weird.
The full Javadoc statement is:
"This builds a document from the supplied Reader. It's the programmer's
responsibility to make sure the reader matches the encoding of the file.
It's always safer to use an InputStream rather than a Reader, if it's
available."
So how about this:
"This builds a document from the supplied Reader. It's the programmer's
responsibility to make sure the reader matches the encoding of the file.
It's often easier to use an InputStream rather than a Reader, and to
let the parser auto-detect the encoding from the XML declaration."
-jh-
More information about the jdom-interest
mailing list