[FIXED JENKINS-4525]

I'd like to believe that the original reason was because earlier
versions of XStream that we used early on didn't support the methods
that take InputStream as a parameter.
This commit is contained in:
Kohsuke Kawaguchi committed 2011-06-28 22:14:03 -07:00
1 parent 39a9b8fe3c
commit 599888fec1
3 files changed
+18 -8

No files matched your search

+12 -6
View File
@@ -27,6 +27,7 @@ import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.io.StreamException;
import com.thoughtworks.xstream.io.xml.XppDriver;
import com.thoughtworks.xstream.io.xml.XppReader;
import hudson.model.Descriptor;
import hudson.util.AtomicFileWriter;
@@ -42,10 +43,12 @@ import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
@@ -123,9 +126,9 @@ public final class XmlFile {
*/
public Object read() throws IOException {
LOGGER.fine("Reading "+file);
Reader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
InputStream in = new BufferedInputStream(new FileInputStream(file));
try {
return xs.fromXML(r);
return xs.fromXML(in);
} catch(StreamException e) {
throw new IOException2("Unable to read "+file,e);
} catch(ConversionException e) {
@@ -133,7 +136,7 @@ public final class XmlFile {
} catch(Error e) {// mostly reflection errors
throw new IOException2("Unable to read "+file,e);
} finally {
r.close();
in.close();
}
}
@@ -145,9 +148,10 @@ public final class XmlFile {
* if the XML representation is completely new.
*/
public Object unmarshal( Object o ) throws IOException {
Reader r = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
InputStream in = new BufferedInputStream(new FileInputStream(file));
try {
return xs.unmarshal(new XppReader(r),o);
// TODO: expose XStream the driver from XStream
return xs.unmarshal(DEFAULT_DRIVER.createReader(in), o);
} catch (StreamException e) {
throw new IOException2("Unable to read "+file,e);
} catch(ConversionException e) {
@@ -155,7 +159,7 @@ public final class XmlFile {
} catch(Error e) {// mostly reflection errors
throw new IOException2("Unable to read "+file,e);
} finally {
r.close();
in.close();
}
}
@@ -295,6 +299,8 @@ public final class XmlFile {
private static final SAXParserFactory JAXP = SAXParserFactory.newInstance();
private static final XppDriver DEFAULT_DRIVER = new XppDriver();
static {
JAXP.setNamespaceAware(true);
}