
co.paralleluniverse.io.serialization.kryo.ExternalizableKryoSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quasar-core Show documentation
Show all versions of quasar-core Show documentation
Fibers, Channels and Actors for the JVM
/*
* Copyright (c) 2013-2014, Parallel Universe Software Co. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 3.0
* as published by the Free Software Foundation.
*/
package co.paralleluniverse.io.serialization.kryo;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import java.io.Externalizable;
import java.io.IOException;
/**
*
* @author pron
*/
public class ExternalizableKryoSerializer extends com.esotericsoftware.kryo.Serializer {
private static final KryoSerializer ks = new KryoSerializer();
@Override
public void write(Kryo kryo, Output output, T obj) {
try {
obj.writeExternal(KryoUtil.asObjectOutput(output, kryo));
} catch (IOException e) {
throw new AssertionError(e);
}
}
@Override
public T read(Kryo kryo, Input input, Class type) {
try {
T obj = kryo.newInstance(type);
obj.readExternal(KryoUtil.asObjectInput(input, kryo));
return obj;
} catch (IOException e) {
throw new AssertionError(e);
} catch (ClassNotFoundException e) {
throw new Error(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy