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

org.aksw.jenax.io.kryo.jena.TupleSerializer Maven / Gradle / Ivy

package org.aksw.jenax.io.kryo.jena;

import org.apache.jena.atlas.lib.tuple.Tuple;
import org.apache.jena.atlas.lib.tuple.TupleFactory;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;

public class TupleSerializer
    extends Serializer>
{
    protected Class componentClass;

    public TupleSerializer(Class componentClass) {
        super();
        this.componentClass = componentClass;
    }

    @Override
    public void write(Kryo kryo, Output output, Tuple object) {
        T[] nodes = object.asArray(componentClass);
        kryo.writeClassAndObject(output, nodes);
    }

    @Override
    public Tuple read(Kryo kryo, Input input, Class> type) {
        @SuppressWarnings("unchecked")
        T[] nodes = (T[])kryo.readClassAndObject(input);
        Tuple result = TupleFactory.create(nodes);
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy