Search in sources :

Example 1 with ObjectMap

use of com.esotericsoftware.kryo.util.ObjectMap in project flink by apache.

the class JavaSerializer method write.

@SuppressWarnings("unchecked")
@Override
public void write(Kryo kryo, Output output, T o) {
    try {
        ObjectMap graphContext = kryo.getGraphContext();
        ObjectOutputStream objectStream = (ObjectOutputStream) graphContext.get(this);
        if (objectStream == null) {
            objectStream = new ObjectOutputStream(output);
            graphContext.put(this, objectStream);
        }
        objectStream.writeObject(o);
        objectStream.flush();
    } catch (Exception ex) {
        throw new KryoException("Error during Java serialization.", ex);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) ObjectMap(com.esotericsoftware.kryo.util.ObjectMap) ObjectOutputStream(java.io.ObjectOutputStream) KryoException(com.esotericsoftware.kryo.KryoException)

Example 2 with ObjectMap

use of com.esotericsoftware.kryo.util.ObjectMap in project flink by apache.

the class JavaSerializer method read.

@SuppressWarnings("unchecked")
@Override
public T read(Kryo kryo, Input input, Class aClass) {
    try {
        ObjectMap graphContext = kryo.getGraphContext();
        ObjectInputStream objectStream = (ObjectInputStream) graphContext.get(this);
        if (objectStream == null) {
            // make sure we use Kryo's classloader
            objectStream = new InstantiationUtil.ClassLoaderObjectInputStream(input, kryo.getClassLoader());
            graphContext.put(this, objectStream);
        }
        return (T) objectStream.readObject();
    } catch (Exception ex) {
        throw new KryoException("Error during Java deserialization.", ex);
    }
}
Also used : InstantiationUtil(org.apache.flink.util.InstantiationUtil) KryoException(com.esotericsoftware.kryo.KryoException) ObjectMap(com.esotericsoftware.kryo.util.ObjectMap) KryoException(com.esotericsoftware.kryo.KryoException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

KryoException (com.esotericsoftware.kryo.KryoException)2 ObjectMap (com.esotericsoftware.kryo.util.ObjectMap)2 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 InstantiationUtil (org.apache.flink.util.InstantiationUtil)1