[jdom-interest] end-of-line character

Alex Chaffee guru at edamame.stinky.com
Thu Jul 6 01:11:33 PDT 2000

On Wed, Jul 05, 2000 at 01:06:11PM -0700, Jason Hunter wrote:
> > I reread the javadoc and println() is what prints platform-dependent
> > line-endings.  The current version of XMLOutputter that I can have
> > (pre-Rusty, I think) uses println() all over, which is correct. 
> Well, why is that "correct"?  Remember, we had this debate after
> Elliotte's change and standardizing on \r\n was fairly well agreed upon
> for numerous reasons.

Well, I remember the debate, but I don't remember losing it :-)

I see Elliotte's point about network protocols and cross-platform
output consistency.  I also see Kevin's (and my) point about local
editors/viewers/processors.  I have been burned by line endings in
both directions.

Let's make it an option.  XMLOutputter should have a
"setLineEnding(String)" method; that should extract a char[] and stash
it in an instance var like the code I posted, for efficiency.

Now the only debate becomes: what should the *default* line ending
sequence be.  Here my reasoning is clear (and hopefully sound):

* JDOM is all about Java

* Java has a system property called "line.separator"

* The value of "line.separator" is used in every java.io class that
has a concept of outputting line endings (to wit, PrintStream and

* Therefore, more people will expect JDOM to use "line.separator" when
outputting lines.

Those who are paranoid, or have platform-independent file
requirements, can say outputter.setLineEnding("\r\n") and everything's
cool and explicit.

The alternative is for those needing platform-dependent files (the
majority IMHO) will have to say
outputter.setLineEnding(System.getProperty("line.separator")) which
seems a little more inelegant to me.

 - Alex

Alex Chaffee                       mailto:alex at jguru.com
jGuru - Java News and FAQs         http://www.jguru.com/alex/
Creator of Gamelan                 http://www.gamelan.com/
Founder of Purple Technology       http://www.purpletech.com/
Curator of Stinky Art Collective   http://www.stinky.com/

More information about the jdom-interest mailing list