Search in sources :

Example 1 with StreamException

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();
    }
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) XppReader(com.thoughtworks.xstream.io.xml.XppReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FileInputStream(java.io.FileInputStream) IOException2(hudson.util.IOException2) StreamException(com.thoughtworks.xstream.io.StreamException)

Example 2 with StreamException

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();
    }
}
Also used : AtomicFileWriter(hudson.util.AtomicFileWriter) IOException2(hudson.util.IOException2) StreamException(com.thoughtworks.xstream.io.StreamException)

Example 3 with StreamException

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;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XStream(com.thoughtworks.xstream.XStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) StreamException(com.thoughtworks.xstream.io.StreamException)

Aggregations

StreamException (com.thoughtworks.xstream.io.StreamException)3 IOException2 (hudson.util.IOException2)2 XStream (com.thoughtworks.xstream.XStream)1 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)1 XppReader (com.thoughtworks.xstream.io.xml.XppReader)1 AtomicFileWriter (hudson.util.AtomicFileWriter)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1