History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-261
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Assignee: Joerg Schaible
Reporter: vieux benou
Votes: 1
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
XStream

Xstream.fromXML(InputStream) should discover the stream encoding, impossible to specify output encoding

Created: 30/Dec/05 05:35 PM   Updated: 25/Feb/08 05:01 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.3

File Attachments: 1. Zip Archive encoding-issue.zip (1 kb)

Issue Links:
Supercedes
 

JDK version and platform: Sun j2sdk1.4.2_09 - windows


 Description  « Hide
Hi,

I'm using xstream for an opensource projet HomePlayer (http://sourceforge.net/projects/homeplayer)

I built xstream from the latest version of the repository to be able to use the methods using InputStream/outputStream instead of Reader/Writer.
(note that the "latest snapshot" from http://xstream.codehaus.org/download.html is an older one)
I found 2 problems.

1) encoding for input streams

the actual implementations of HierarchicalStreamDriver classes are generally using the default encoding for reading InputStream. Here is an extract from XppDriver :

    public HierarchicalStreamReader createReader(InputStream in) {
        return createReader(new InputStreamReader(in));
    }

By using the the InputStreamReader constructor without specifing an encoding, the default encoding of the computer is used, so if the specified InputStream comes from a File that is not using the default encoding, some special caracters will be read baddly.

I could fix it for the DomDriver because the standard XML parsers include the mechanism of reading the XML declaration to know which encoding is used. The solution is to create an InputSource without setting the encoding.

I attach a test case to show the problem and a patch for the DomDriver.
The problem still remains for other HierarchicalStreamDrivers


2) encoding for output streams.

I need Xstream to save the xml data in files and to use theses files on others computers that do not use the same default encoding. To ensure the files are correctly read, they have to contain the xml declaration to specify their encoding.
I can't find a way to ask xstream to write this xml decalration.

In my opinion, their should be a parameter for xstream to unable the user to say if he wants xstream to add the xml declaration or not.

Plus, I think an other method should be added to the xstream class to allow to write an xml data to an OutputStream using a specific encoding :
public void toXML(java.lang.Object obj, java.io.OutputStream out, java.lang.String encoding)

Cheers,
Benou

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
vieux benou - 30/Dec/05 06:13 PM
note that you should include to the classpath the root of the extracted directory, otherwise the xml files won't be found and NPE will occur (I did not check that in the test case)

Mauro Talevi - 13/Jan/06 03:30 AM
These changes involve API signatures so are best suited for 1.2 release.

Also, we should find a solution which is valid for all drivers - not just DomDriver.


Joerg Schaible - 13/Feb/08 03:53 PM
All Drivers will respect now the encoding of the XML header if an InputStream is provided.

Joerg Schaible - 25/Feb/08 05:01 PM
Closing issues before next release.