Search in sources :

Example 31 with DomDriver

use of com.thoughtworks.xstream.io.xml.DomDriver in project GDSC-SMLM by aherbert.

the class ImageSource method fromXml.

/**
 * Create the image source from serialised XML.
 *
 * @param xml the xml
 * @return the image source
 * @see #toXml()
 */
public static ImageSource fromXml(String xml) {
    final XStream xs = new XStream(new DomDriver());
    try {
        xs.allowTypesByWildcard(new String[] { "uk.ac.sussex.gdsc.smlm.**" });
        xs.autodetectAnnotations(true);
        // Support package gdsc.smlm renamed to uk.ac.sussex.gdsc.smlm
        return (ImageSource) xs.fromXML(XStreamUtils.updateGdscPackageName(xml));
    } catch (final Exception ex) {
        Logger.getLogger(ImageSource.class.getName()).log(Level.SEVERE, "Failed to deserialise from XML", ex);
    }
    return null;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream) XStreamException(com.thoughtworks.xstream.XStreamException)

Example 32 with DomDriver

use of com.thoughtworks.xstream.io.xml.DomDriver in project GDSC-SMLM by aherbert.

the class PcPalmAnalysis method loadResults.

/**
 * Load all the results from a directory. File must have the XML suffix.
 *
 * @param results the results
 * @return the updated results
 */
private List<CorrelationResult> loadResults(final List<CorrelationResult> results) {
    if (getDirectory()) {
        final File[] fileList = (new File(settings.resultsDirectory)).listFiles((arg0, arg1) -> arg1.endsWith("xml"));
        if (fileList == null) {
            return results;
        }
        // New list
        final List<CorrelationResult> newResults = new ArrayList<>(results);
        int count = 0;
        for (int i = 0; i < fileList.length; i++) {
            final XStream xs = new XStream(new DomDriver());
            // to be removed after 1.5
            XStream.setupDefaultSecurity(xs);
            xs.allowTypes(new Class[] { CorrelationResult.class });
            if (fileList[i].isFile() && loadResult(newResults, xs, fileList[i].getPath())) {
                count++;
            }
        }
        if (count > 0) {
            Collections.sort(newResults, CorrelationResult::compare);
        }
        log("Loaded %d results", count);
        return newResults;
    }
    return results;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

XStream (com.thoughtworks.xstream.XStream)32 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)32 IOException (java.io.IOException)8 Gson (com.google.gson.Gson)5 File (java.io.File)5 InputStream (java.io.InputStream)5 ObjectInputStream (java.io.ObjectInputStream)5 GsonBuilder (com.google.gson.GsonBuilder)4 Binder (net.sergeych.tools.Binder)4 Yaml (org.yaml.snakeyaml.Yaml)4 HttpClient (org.apache.commons.httpclient.HttpClient)3 HttpException (org.apache.commons.httpclient.HttpException)3 HttpMethod (org.apache.commons.httpclient.HttpMethod)3 GetMethod (org.apache.commons.httpclient.methods.GetMethod)3 XStreamException (com.thoughtworks.xstream.XStreamException)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 BackingStoreException (java.util.prefs.BackingStoreException)2 OptionException (joptsimple.OptionException)2 BiDeserializer (net.sergeych.biserializer.BiDeserializer)2