All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.boon.slumberdb.serialization.KryoObjectToByteArrayConverter Maven / Gradle / Ivy

package org.boon.slumberdb.serialization;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Output;
import org.boon.core.Function;

import java.io.ByteArrayOutputStream;

/**
 * Created by Richard on 4/9/14.
 */
public class KryoObjectToByteArrayConverter implements Function {
    private final Kryo kryo;
    private final Class type;

    public KryoObjectToByteArrayConverter(Kryo kryo, Class type) {
        this.kryo = kryo;
        this.type = type;
    }

    @Override
    public byte[] apply(T value) {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Output streamOut = new Output(baos);
        this.kryo.writeObject(streamOut, value);
        streamOut.close();
        return baos.toByteArray();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy