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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations