It's not that using a Writer is not a rational choice. One can imagine situations where a Writer is perfectly rationale (where the default encodings really are desireable, or instantiating the Writer with an OutputStreamWriter with an explicit encoding). It's just usually unecessary, and usually the wrong choice. And I think I was wrong, omitting the Writer-based methods from the serializer API would have been a bad idea. The problem is there is no Java bridge for chaining a Writer to a stream (as far as I know).
Suppose you're not serializing to a Writer under your control, but one provided to you by another API, and it offers a Writer but not a Stream (probably a bad choice on the API's part, but concievable). The lack of Writer methods on the serializer API would force you to use some intermediary buffer and a loop through writing the bytes from the serialized Stream to the Writer. (The same issue applies to reading the XML in, and thus you can parse from an InputSource instantiated from a Reader.) As others have said, you're not dealing with a bug in any of these APIs. A confluence of unfortunate design choices, perhaps, starting with OSes that default to non-unicode encodings, to some aspects of Java's Reader/Writer API. I wouldn't fault the serializer at all, except perhaps that the caveats in the documentation should be more emphatic, since this really IS a common pitfall. Eric Graham Leggett wrote: >Eric Schwarzenbach said: > > > >>Omitting all the Writer-based methods to encourage Stream usage wouldn't >>have been a bad idea either (like DocumentBuilder and SAXParser for the >>same problem on the other end). But it's a bit late now I suppose. >> >> > >I would say these methods should be deprecated and removed in a future >release. > >If I had seen the Writer methods were deprecated, I would never have used >them in the first place. > > > >>Over the years, I've seen probably every programmer new to XML fall into >>the same pitfall when they try do this. "Well this is text, it makes the >>most sense to use the Writer version...", they inevitably think, and it >>often takes a lot of explaining to convince them otherwise. I shudder to >>imagine how many wrong implementations there are out there because it >>works most of the time. >> >> > >I'm not new to XML, but certainly new to the subtleties of unicode. The >Principle of Least Astonishment should apply to this. There is no obvious >reason why a Writer should not be a rational choice for XML, especially >considering that a Writer is an officially supported by the >implementation. If it's not a rational choice (as has been pointed out), >then don't support it. > >People have argued "it's documented", but then what programmer looks for >documentation before the fact to to solve a bug they don't even know is >there? > >Regards, >Graham >-- > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
