use of com.thoughtworks.xstream.io.StreamException in project hudson-2.x by hudson.
the class XmlFile method read.
/**
* Loads the contents of this file into a new object.
*/
public Object read() throws IOException {
LOGGER.fine("Reading " + file);
Reader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
try {
return xs.fromXML(r);
} catch (StreamException e) {
throw new IOException2("Unable to read " + file, e);
} catch (ConversionException e) {
throw new IOException2("Unable to read " + file, e);
} catch (Error e) {
// mostly reflection errors
throw new IOException2("Unable to read " + file, e);
} finally {
r.close();
}
}
use of com.thoughtworks.xstream.io.StreamException in project hudson-2.x by hudson.
the class XmlFile method write.
public void write(Object o) throws IOException {
mkdirs();
AtomicFileWriter w = new AtomicFileWriter(file);
try {
w.write("<?xml version='1.0' encoding='UTF-8'?>\n");
xs.toXML(o, w);
w.commit();
} catch (StreamException e) {
throw new IOException2(e);
} finally {
w.abort();
}
}
use of com.thoughtworks.xstream.io.StreamException in project jmeter by apache.
the class TemplateManager method initXStream.
private XStream initXStream() {
XStream xstream = new XStream(new DomDriver() {
/**
* Create the DocumentBuilderFactory instance.
* See https://blog.compass-security.com/2012/08/secure-xml-parser-configuration/
* See https://github.com/x-stream/xstream/issues/25
* @return the new instance
*/
@Override
protected DocumentBuilderFactory createDocumentBuilderFactory() {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
} catch (ParserConfigurationException e) {
throw new StreamException(e);
}
factory.setExpandEntityReferences(false);
return factory;
}
});
xstream.alias("template", Template.class);
xstream.alias("templates", Templates.class);
xstream.useAttributeFor(Template.class, "isTestPlan");
// templates i
xstream.addImplicitMap(Templates.class, // $NON-NLS-1$
"templates", Template.class, // $NON-NLS-1$
"name");
return xstream;
}
Aggregations