Search in sources :

Example 1 with BatfishObjectInputStream

use of org.batfish.common.util.BatfishObjectInputStream 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)

Aggregations

XStream (com.thoughtworks.xstream.XStream)1 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)1 ObjectInputStream (java.io.ObjectInputStream)1 BatfishException (org.batfish.common.BatfishException)1 BatfishObjectInputStream (org.batfish.common.util.BatfishObjectInputStream)1