use of com.thoughtworks.xstream.io.xml.DomDriver in project JavaYouShouldKnow by CFMystery.
the class XStreamXML method getFromObject.
public Object getFromObject(String path) throws IOException {
FileInputStream inputStream = new FileInputStream(new File(path));
XStream xStream = new XStream(new DomDriver());
return xStream.fromXML(inputStream);
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project JavaYouShouldKnow by CFMystery.
the class XStreamXML method saveToXML.
public void saveToXML(Object o) throws IOException {
XStream xStream = new XStream(new DomDriver());
File xmlFile = new File("file/out/xStream-object.xml");
FileOutputStream ofs = new FileOutputStream(xmlFile);
xStream.toXML(o, ofs);
ofs.close();
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project batfish by batfish.
the class PluginConsumer method deserializeObject.
private <S extends Serializable> S deserializeObject(InputStream stream, Class<S> outputClass, Format format) throws IOException {
try {
ObjectInputStream ois;
if (format != Format.JAVA_SERIALIZED) {
XStream xstream = new XStream(new DomDriver("UTF-8"));
xstream.setClassLoader(_currentClassLoader);
ois = xstream.createObjectInputStream(stream);
} else {
ois = new BatfishObjectInputStream(stream, _currentClassLoader);
}
Object o = ois.readObject();
return outputClass.cast(o);
} catch (ClassNotFoundException | ClassCastException e) {
throw new BatfishException("Failed to deserialize object of type '" + outputClass.getCanonicalName() + "' from data", e);
}
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project data-access by pentaho.
the class CsvUtils method getModelInfo.
public ModelInfo getModelInfo(String project, String filename) throws FileNotFoundException {
// $NON-NLS-1$
XStream xstream = new XStream(new DomDriver("UTF-8"));
// $NON-NLS-1$
xstream.alias("modelInfo", ModelInfo.class);
// $NON-NLS-1$
xstream.alias("columnInfo", ColumnInfo.class);
// $NON-NLS-1$ //$NON-NLS-2$
String filepath = AgileHelper.getFolderPath(project) + "/" + filename + ".xml";
System.out.println(filepath);
File f = new File(filepath);
FileInputStream fis = new FileInputStream(f);
return (ModelInfo) xstream.fromXML(fis);
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project GDSC-SMLM by aherbert.
the class ImageSource method toXml.
/**
* Serialise to XML.
*
* @return An XML representation of this object
* @see #fromXml(String)
*/
public String toXml() {
final XStream xs = new XStream(new DomDriver());
try {
xs.allowTypesByWildcard(new String[] { "uk.ac.sussex.gdsc.smlm.**" });
xs.autodetectAnnotations(true);
return xs.toXML(this);
} catch (final XStreamException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Failed to serialise to XML", ex);
}
return "";
}
Aggregations