Search in sources :

Example 46 with XStream

use of com.thoughtworks.xstream.XStream in project GDSC-SMLM by aherbert.

the class SettingsManager method saveSettings.

/**
	 * Save the settings to file.
	 * <p>
	 * If this fails then an error message is written to the ImageJ log
	 *
	 * @param settings
	 *            the settings
	 * @param filename
	 *            the filename
	 * @param silent
	 *            Set to true to suppress writing an error message to the ImageJ log
	 * @return True if saved
	 */
public static boolean saveSettings(GlobalSettings settings, String filename, boolean silent) {
    XStream xs = createXStream();
    FileOutputStream fs = null;
    try {
        fs = new FileOutputStream(filename);
        xs.toXML(settings, fs);
        return true;
    } catch (FileNotFoundException ex) {
    //ex.printStackTrace();
    } catch (XStreamException ex) {
        ex.printStackTrace();
    } finally {
        if (fs != null) {
            try {
                fs.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (!silent)
        IJ.log("Unable to save settings to: " + filename);
    return false;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) XStream(com.thoughtworks.xstream.XStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 47 with XStream

use of com.thoughtworks.xstream.XStream in project GDSC-SMLM by aherbert.

the class SettingsManager method unsafeLoadSettings.

/**
	 * Load the settings within the specified file
	 * <p>
	 * If this fails then an error message is written to the ImageJ log
	 * 
	 * @param filename
	 * @param silent
	 *            Set to true to suppress writing an error message to the ImageJ log
	 * @return The settings (or null)
	 */
public static GlobalSettings unsafeLoadSettings(String filename, boolean silent) {
    XStream xs = createXStream();
    GlobalSettings config = null;
    FileInputStream fs = null;
    try {
        fs = new FileInputStream(filename);
        config = (GlobalSettings) xs.fromXML(fs);
    } catch (ClassCastException ex) {
    //ex.printStackTrace();
    } catch (FileNotFoundException ex) {
    //ex.printStackTrace();
    } catch (XStreamException ex) {
        ex.printStackTrace();
    } finally {
        if (fs != null) {
            try {
                fs.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (config == null)
        if (!silent)
            IJ.log("Unable to load settings from: " + filename);
    return config;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) XStream(com.thoughtworks.xstream.XStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 48 with XStream

use of com.thoughtworks.xstream.XStream in project GDSC-SMLM by aherbert.

the class SettingsManager method saveFitEngineConfiguration.

/**
	 * Save the configuration to file
	 * 
	 * @param config
	 * @param filename
	 * @return True if saved
	 */
public static boolean saveFitEngineConfiguration(FitEngineConfiguration config, String filename) {
    XStream xs = createXStream();
    FileOutputStream fs = null;
    try {
        fs = new FileOutputStream(filename);
        xs.toXML(config, fs);
        return true;
    } catch (FileNotFoundException ex) {
    //ex.printStackTrace();
    } catch (XStreamException ex) {
        ex.printStackTrace();
    } finally {
        if (fs != null) {
            try {
                fs.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return false;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) XStream(com.thoughtworks.xstream.XStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 49 with XStream

use of com.thoughtworks.xstream.XStream in project GDSC-SMLM by aherbert.

the class CreateData method createXStream.

private XStream createXStream() {
    if (xs == null) {
        xs = new XStream(new DomDriver());
        xs.autodetectAnnotations(true);
        xs.alias("Compound", Compound.class);
        xs.alias("Atom", Atom.class);
    }
    return xs;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream)

Example 50 with XStream

use of com.thoughtworks.xstream.XStream in project maven-plugins by apache.

the class EvaluateMojo method getXStream.

/**
     * @return lazy loading xstream object.
     */
private XStream getXStream() {
    if (xstream == null) {
        xstream = new XStream();
        addAlias(xstream);
        // handle Properties a la Maven
        xstream.registerConverter(new PropertiesConverter() {

            /** {@inheritDoc} */
            public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
                return Properties.class == type;
            }

            /** {@inheritDoc} */
            public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
                Properties properties = (Properties) source;
                // sort
                Map<?, ?> map = new TreeMap<Object, Object>(properties);
                for (Map.Entry<?, ?> entry : map.entrySet()) {
                    writer.startNode(entry.getKey().toString());
                    writer.setValue(entry.getValue().toString());
                    writer.endNode();
                }
            }
        });
    }
    return xstream;
}
Also used : JarEntry(java.util.jar.JarEntry) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) Properties(java.util.Properties) PropertiesConverter(com.thoughtworks.xstream.converters.collections.PropertiesConverter) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

XStream (com.thoughtworks.xstream.XStream)199 Test (org.junit.Test)55 IOException (java.io.IOException)33 InputStream (java.io.InputStream)29 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)22 Metacard (ddf.catalog.data.Metacard)21 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)17 HashMap (java.util.HashMap)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)12 XStreamUtils.createTrustingXStream (org.kie.soup.commons.xstream.XStreamUtils.createTrustingXStream)12 Matchers.anyString (org.mockito.Matchers.anyString)11 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)10 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)10 FileNotFoundException (java.io.FileNotFoundException)9 Writer (java.io.Writer)8 ArrayList (java.util.ArrayList)8 GmlGeometryConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter)8 XStreamException (com.thoughtworks.xstream.XStreamException)7 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)7