[jdom-interest] XMLOutputter clipping text ... a bug?
William Krick
wkrick at eio-online.com
Tue Mar 9 10:20:07 PST 2004
Ok, I seem to have fixed the problem
but I'm at a loss as to _WHY_ this fixes it.
I changed the following line...
XMLOutputter fmt = new XMLOutputter();
...to...
XMLOutputter fmt = new XMLOutputter("", false, "UTF-8");
...and the problem seems to be gone.
The "byte order mark" FF FE is still there when viewed
in a hex editor but the XML output is no longer clipped
at the beginning.
-----Original Message-----
From: jdom-interest-admin at jdom.org
[mailto:jdom-interest-admin at jdom.org]On Behalf Of Jason Hunter
Sent: Friday, March 05, 2004 8:01 PM
To: William Krick
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] XMLOutputter clipping text ... a bug?
That's a byte order mark, used in UTF-8 output.
-jh-
William Krick wrote:
> Ok, more strangeness...
>
> I opened the output file in a hex editor.
>
> There are two characters before my ascii XML begins: FF FE (in hex)
>
> This makes no sense at all.
>
> ...
> Krick
>
>
>
>
> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of William Krick
> Sent: Friday, March 05, 2004 6:29 PM
> To: Jason Hunter
> Cc: jdom-interest at jdom.org
> Subject: RE: [jdom-interest] XMLOutputter clipping text ... a bug?
>
>
> I modified my sample code to fill a buffer directly from the
FileInputStream
> and then write it directly to the FileOutputStream, eliminating the
> XMLOutputter from the equasion. It works correctly. So the problem has
> something to do with the way XMLOutputter talks to FileOutputStream...
>
>
> String fileName = "test.xml";
> File f = null;
> int c;
> int[] buffer = new int[4096];
> int size = 0;
>
> //load the data from the xml file
> FileInputStream fis = null;
> try {
> f = new File(fileName);
> fis = new FileInputStream(f);
>
> int i=0;
> while ((c = fis.read()) != -1) {
> buffer[i] = c;
> i++;
> }
> size = i;
> }
> catch (Exception ex) {
> }
> finally {
> try { fis.close(); } catch (Exception ex) {}
> }
>
> // write the data back out to the file
> FileOutputStream fos = null;
> try {
> f = new File(fileName);
> fos = new FileOutputStream(f);
>
> int i=0;
> while (size-i > 0) {
> fos.write(buffer[i]);
> i++;
> }
> }
> catch (Exception ex) {
> }
> finally {
> try { fos.close(); } catch (Exception ex) {}
> }
>
>
>
>
> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of William Krick
> Sent: Friday, March 05, 2004 4:50 PM
> To: Jason Hunter
> Cc: jdom-interest at jdom.org
> Subject: RE: [jdom-interest] XMLOutputter clipping text ... a bug?
>
>
> It comes out fine in system out but not in the file.
>
> If I send the output to a different file instead of the same file, it
works
> correctly.
>
> I would think that as long as I close the FileInputStream before I open
the
> FileOutputStream, it should be okay using the same file.
>
> I'm at a loss as to what the heck is happening here.
>
>
>
>
> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Jason Hunter
> Sent: Friday, March 05, 2004 4:42 PM
> To: William Krick
> Cc: jdom-interest at jdom.org
> Subject: Re: [jdom-interest] XMLOutputter clipping text ... a bug?
>
>
> I've never heard of this before. I'm going to guess it has to do with
> your stream. Dump it to System.out for another view.
>
> -jh-
>
> William Krick wrote:
>
>
>>Using JDOM b9, when I run an xml file...
>>
>>-----begin test.xml-----
>><?xml version="1.0" encoding="UTF-8"?><TEST>This is a test.</TEST>
>>------end test.xml------
>>
>>...through the following code...
>>
>>
>> String fileName = "test.xml";
>> File f = new File(fileName);
>> Document doc = null;
>>
>> //load the doc from the xml file
>> SAXBuilder builder = new SAXBuilder();
>> FileInputStream fis = null;
>> try {
>> fis = new FileInputStream(f);
>> doc = builder.build(fis);
>> }
>> catch (Exception ex) {
>> }
>> finally {
>> try { fis.close(); } catch (Exception ex) {}
>> }
>>
>> //
>> // you would do stuff to the doc here
>> //
>>
>>
>> // write the doc back out to the file
>> XMLOutputter fmt = new XMLOutputter();
>> FileOutputStream fos = null;
>> try {
>> fos = new FileOutputStream(f);
>> fmt.output(doc, fos);
>> }
>> catch (Exception ex) {
>> }
>> finally {
>> try { fos.close(); } catch (Exception ex) {}
>> }
>>
>>
>>... it comes out with the beginning of the text clipped like this...
>>
>>-----begin test.xml-----
>>ml version="1.0" encoding="UTF-8"?><TEST>This is a test.</TEST>
>>------end test.xml------
>>
>>
>>
>>Is this a bug or am I doing something wrong? This is REALLY frustrating.
>>
>>...
>>Krick
>>
>>_______________________________________________
>>To control your jdom-interest membership:
>>
>
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
> t.com
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
> t.com
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
> t.com
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
> t.com
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
>
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
More information about the jdom-interest
mailing list