1. XStream
  2. XSTR-261

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


    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3
    • Component/s: None
    • Labels:
    • JDK version and platform:
      Sun j2sdk1.4.2_09 - windows



      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)


        Issue Links


          • Assignee:
            Jörg Schaible
            vieux benou
          • Votes:
            1 Vote for this issue
            3 Start watching this issue


            • Created: