[jdom-interest] PrintWriter in XMLOutputter

Elliotte Rusty Harold elharo at metalab.unc.edu
Mon Jun 19 16:52:10 PDT 2000

I'm looking at XMLOutputter right now, and I'm wondering why it makes
such heavy use of PrintWriter? It doesn't seem to really need it, and
this has the, to my mind, nasty effect of hiding any IOExceptions that
may occur when the document is written. For instance, if I'm writing to
a network socket and the phone company cuts off my phone line in the
middle of my write, I won't get notified that the write failed. 

Wouldn't it be better to use OutputStreamWriter instead, which doesn't
suppress IOExceptions, so that programmers will be warned if their
writes fail? The output() method is already declared to throw
IOExceptions, so this is not an API change for the public API, but in
practice output() will almost never throw an IOException as currently
written. The protected API would have to change but that's a relatively
minor loss. 

| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
|               Java I/O (O'Reilly & Associates, 1999)               |
|            http://metalab.unc.edu/javafaq/books/javaio/            |
|   http://www.amazon.com/exec/obidos/ISBN=1565924851/cafeaulaitA/   |
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ | 
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |

More information about the jdom-interest mailing list