Search in sources :

Example 26 with DomDriver

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);
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 27 with DomDriver

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();
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 28 with DomDriver

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);
    }
}
Also used : BatfishObjectInputStream(org.batfish.common.util.BatfishObjectInputStream) BatfishException(org.batfish.common.BatfishException) DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream) ObjectInputStream(java.io.ObjectInputStream) BatfishObjectInputStream(org.batfish.common.util.BatfishObjectInputStream)

Example 29 with DomDriver

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);
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) XStream(com.thoughtworks.xstream.XStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 30 with DomDriver

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 "";
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStreamException(com.thoughtworks.xstream.XStreamException) XStream(com.thoughtworks.xstream.XStream)

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