Search in sources :

Example 1 with LZ4FrameOutputStream

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);
    }
}
Also used : Closer(com.google.common.io.Closer) BatfishException(org.batfish.common.BatfishException) DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream) LZ4FrameOutputStream(net.jpountz.lz4.LZ4FrameOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) FilterOutputStream(java.io.FilterOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) LZ4FrameOutputStream(net.jpountz.lz4.LZ4FrameOutputStream)

Aggregations

Closer (com.google.common.io.Closer)1 XStream (com.thoughtworks.xstream.XStream)1 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FilterOutputStream (java.io.FilterOutputStream)1 IOException (java.io.IOException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 LZ4FrameOutputStream (net.jpountz.lz4.LZ4FrameOutputStream)1 BatfishException (org.batfish.common.BatfishException)1