[jdom-interest] Dealing with binary characters in-memory -> outputter, Sample Code, Findings

Attila Szegedi szegedia at freemail.hu
Wed Sep 26 01:12:21 PDT 2001


----- Original Message -----
From: "Mark Bennett" <mbennett at ideaeng.com>
To: "Jason Hunter" <jhunter at acm.org>
Cc: <jdom-interest at jdom.org>; "Mark Bennett" <mbennett at ideaeng.com>
Sent: 2001. szeptember 26. 5:48
Subject: RE: [jdom-interest] Dealing with binary characters in-memory ->
outputter, Sample Code, Findings


>
> Discovery # 3: (at least for me)
> It makes a difference whether you use a Java output stream or
> a Java "writer".
>
> If I send XMLOutputter xo.output() a plain FileOutputStream
> it works just fine!  I do get the propper 2 character sequence.
>
> If I send xo.output() an OutputStreamWriter created from an
> a BufferedOutputStream it breaks.  This is what I was doing
> wrong; I had thought the buffering would be important to have
> and didn't set any code page stuff.
>
> Works:
> OutputStream outStream = new FileOutputStream( new File("test.xml") );
> xo.output( doc, outStream );
>
> Breaks:
> OutputStream outStream = new FileOutputStream( new File("test.xml") );
> // Extra steps from old code
> OutputStream bOutStream = new BufferedOutputStream( outStream );
> Writer writer = new OutputStreamWriter( bOutStream );
> xo.output( doc, writer );
>

But
  Writer writer = new OutputStreamWriter( bOutStream , "UTF-8");
will work.
You apparently forgot my advice from my first reply to your problem
(repeated):
"I hope you're aware that in order to have XMLOutputter use specific
encoding, you must specify the encoding BOTH to a Writer AND to the
XMLOutputter setEncoding".

Attila.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2848 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20010926/5647f852/smime.bin


More information about the jdom-interest mailing list