use of net.jpountz.lz4.LZ4FrameOutputStream in project batfish by batfish.
the class PluginConsumer method serializeToLz4Data.
/**
* Serializes the given object to the given stream, using LZ4 compression.
*/
private void serializeToLz4Data(Serializable object, OutputStream out) {
// This is a hack:
// XStream requires that its streams be closed to properly finish serialization,
// but we do not actually want to close the passed-in output stream.
out = new CloseIgnoringOutputStream(out);
try (Closer closer = Closer.create()) {
OutputStream los = closer.register(new LZ4FrameOutputStream(out));
ObjectOutputStream oos;
if (_serializeToText) {
XStream xstream = new XStream(new DomDriver("UTF-8"));
oos = closer.register(xstream.createObjectOutputStream(los));
} else {
oos = closer.register(new ObjectOutputStream(los));
}
oos.writeObject(object);
} catch (IOException e) {
throw new BatfishException("Failed to convert object to LZ4 data", e);
}
}
Aggregations