[jdom-interest] XMLOutputter & StringWriter

Jason Hunter jhunter at collab.net
Mon Jul 3 10:07:55 PDT 2000


Gabor Greif wrote:
> 
> On Thu, Jun 29, 2000 22:05 Uhr, Jason Hunter <mailto:jhunter at collab.net>
> wrote:
> >There's an output(Document, Writer) method in the CVS tree.
> >
> >-jh-
> 
> Sorry, but I cannot see it :-(
> 
> I am looking at revision 1.9 of XMLOutputter.java
> There are only two output methods and both take an OutputStream.
> 
> Are you sure you checked in?

Ah, you're right.  Sorry about the miscommunication.  Elliotte changed
the class to use a Writer internally but the public API lacks a method
that accepts a Writer.  So what do people think of adding output()
methods that accept Writers?  I think it'd be a fine addition, but with
one twist.  I propose we don't provide

output(Document, Writer)

and only provide

output(Document, Writer, String encodingOfWriter)

This is because the top method requires the Writer to be a Writer for
the same encoding that we have as default (UTF-8), or the encoding that
was passed in to the constructor (could be anything).  That seems
awfully risky.  Forcing you to specify will keep people from calling
this in a servlet:

outputter.output(doc, res.getWriter())

It seems perfectly reasonable, but since we default to UTF-8 and
servlets default to Latin-1, you'll have serious problems.  Opinions?

-jh-



More information about the jdom-interest mailing list