Search in sources :

Example 1 with Kryo

use of com.esotericsoftware.kryo.Kryo in project flink by apache.

the class StateDescriptorPassingTest method validateStateDescriptorConfigured.

// ------------------------------------------------------------------------
//  generic validation
// ------------------------------------------------------------------------
private void validateStateDescriptorConfigured(SingleOutputStreamOperator<?> result) {
    OneInputTransformation<?, ?> transform = (OneInputTransformation<?, ?>) result.getTransformation();
    WindowOperator<?, ?, ?, ?, ?> op = (WindowOperator<?, ?, ?, ?, ?>) transform.getOperator();
    StateDescriptor<?, ?> descr = op.getStateDescriptor();
    // this would be the first statement to fail if state descriptors were not properly initialized
    TypeSerializer<?> serializer = descr.getSerializer();
    assertTrue(serializer instanceof KryoSerializer);
    Kryo kryo = ((KryoSerializer<?>) serializer).getKryo();
    assertTrue("serializer registration was not properly passed on", kryo.getSerializer(File.class) instanceof JavaSerializer);
}
Also used : WindowOperator(org.apache.flink.streaming.runtime.operators.windowing.WindowOperator) OneInputTransformation(org.apache.flink.streaming.api.transformations.OneInputTransformation) JavaSerializer(com.esotericsoftware.kryo.serializers.JavaSerializer) Kryo(com.esotericsoftware.kryo.Kryo) KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer)

Example 2 with Kryo

use of com.esotericsoftware.kryo.Kryo in project storm by apache.

the class KinesisConnectionInfo method getKryoDeserializedObject.

private Object getKryoDeserializedObject(final byte[] ser) {
    final Kryo kryo = new Kryo();
    final Input input = new Input(new ByteArrayInputStream(ser));
    kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
    return kryo.readClassAndObject(input);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) StdInstantiatorStrategy(org.objenesis.strategy.StdInstantiatorStrategy) ByteArrayInputStream(java.io.ByteArrayInputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Example 3 with Kryo

use of com.esotericsoftware.kryo.Kryo in project hive by apache.

the class TestInputOutputFormat method toKryo.

public static String toKryo(SearchArgument sarg) {
    Output out = new Output(4 * 1024, 10 * 1024 * 1024);
    new Kryo().writeObject(out, sarg);
    out.close();
    return Base64.encodeBase64String(out.toBytes());
}
Also used : DataOutput(java.io.DataOutput) Output(com.esotericsoftware.kryo.io.Output) Kryo(com.esotericsoftware.kryo.Kryo)

Example 4 with Kryo

use of com.esotericsoftware.kryo.Kryo in project hive by apache.

the class KryoSerializer method serialize.

public static byte[] serialize(Object object) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Output output = new Output(stream);
    Kryo kryo = SerializationUtilities.borrowKryo();
    kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
    try {
        kryo.writeObject(output, object);
    } finally {
        SerializationUtilities.releaseKryo(kryo);
    }
    // close() also calls flush()
    output.close();
    return stream.toByteArray();
}
Also used : Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Example 5 with Kryo

use of com.esotericsoftware.kryo.Kryo in project hive by apache.

the class KryoSerializer method deserialize.

public static <T> T deserialize(byte[] buffer, Class<T> clazz) {
    Kryo kryo = SerializationUtilities.borrowKryo();
    kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
    T result = null;
    try {
        result = kryo.readObject(new Input(new ByteArrayInputStream(buffer)), clazz);
    } finally {
        SerializationUtilities.releaseKryo(kryo);
    }
    return result;
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Aggregations

Kryo (com.esotericsoftware.kryo.Kryo)71 Input (com.esotericsoftware.kryo.io.Input)31 Output (com.esotericsoftware.kryo.io.Output)29 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 ByteArrayInputStream (java.io.ByteArrayInputStream)16 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)13 Test (org.junit.Test)10 Test (org.testng.annotations.Test)8 ArrayList (java.util.ArrayList)6 BigIntegerSerializer (com.esotericsoftware.kryo.serializers.DefaultSerializers.BigIntegerSerializer)5 File (java.io.File)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 List (java.util.List)5 Map (java.util.Map)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 ArrayListSerializer (backtype.storm.serialization.types.ArrayListSerializer)3 HashMapSerializer (backtype.storm.serialization.types.HashMapSerializer)3 HashSetSerializer (backtype.storm.serialization.types.HashSetSerializer)3 Serializer (com.esotericsoftware.kryo.Serializer)3