use of com.esotericsoftware.kryo.io.Input in project heron by twitter.
the class HeronPluggableSerializerDelegate method initialize.
@Override
@SuppressWarnings("rawtypes")
public void initialize(Map config) {
kryo = SerializationFactory.getKryo(config);
kryoOut = new Output(2000, 2000000000);
kryoIn = new Input(1);
}
use of com.esotericsoftware.kryo.io.Input in project quasar by puniverse.
the class KryoSerializer method read.
public <T> T read(InputStream is, Class<T> type) {
final Input in = getInput();
in.setInputStream(is);
return kryo.readObjectOrNull(input, type);
}
use of com.esotericsoftware.kryo.io.Input in project quasar by puniverse.
the class KryoSerializer method read.
@Override
public Object read(InputStream is) throws IOException {
final Input in = getInput();
in.setInputStream(is);
return kryo.readClassAndObject(in);
}
use of com.esotericsoftware.kryo.io.Input in project jetcache by alibaba.
the class KryoValueDecoder method apply.
@Override
public Object apply(byte[] buffer) {
try {
checkHeader(buffer, KryoValueEncoder.IDENTITY_NUMBER);
ByteArrayInputStream in = new ByteArrayInputStream(buffer, 4, buffer.length - 4);
Input input = new Input(in);
Kryo kryo = KryoValueEncoder.kryoThreadLocal.get();
return kryo.readClassAndObject(input);
} catch (Exception e) {
throw new CacheEncodeException("Kryo decode error: " + e.getMessage(), e);
}
}
use of com.esotericsoftware.kryo.io.Input in project beam by apache.
the class AvroCoderTest method testKryoSerialization.
/**
* Confirm that we can serialize and deserialize an AvroCoder object using Kryo.
* (BEAM-626).
*
* @throws Exception
*/
@Test
public void testKryoSerialization() throws Exception {
Pojo value = new Pojo("Hello", 42);
AvroCoder<Pojo> coder = AvroCoder.of(Pojo.class);
//Kryo instantiation
Kryo kryo = new Kryo();
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
//Serialization of object without any memoization
ByteArrayOutputStream coderWithoutMemoizationBos = new ByteArrayOutputStream();
try (Output output = new Output(coderWithoutMemoizationBos)) {
kryo.writeObject(output, coder);
}
// Force thread local memoization to store values.
CoderProperties.coderDecodeEncodeEqual(coder, value);
// Serialization of object with memoized fields
ByteArrayOutputStream coderWithMemoizationBos = new ByteArrayOutputStream();
try (Output output = new Output(coderWithMemoizationBos)) {
kryo.writeObject(output, coder);
}
// Copy empty and memoized variants of the Coder
ByteArrayInputStream bisWithoutMemoization = new ByteArrayInputStream(coderWithoutMemoizationBos.toByteArray());
AvroCoder<Pojo> copiedWithoutMemoization = (AvroCoder<Pojo>) kryo.readObject(new Input(bisWithoutMemoization), AvroCoder.class);
ByteArrayInputStream bisWithMemoization = new ByteArrayInputStream(coderWithMemoizationBos.toByteArray());
AvroCoder<Pojo> copiedWithMemoization = (AvroCoder<Pojo>) kryo.readObject(new Input(bisWithMemoization), AvroCoder.class);
CoderProperties.coderDecodeEncodeEqual(copiedWithoutMemoization, value);
CoderProperties.coderDecodeEncodeEqual(copiedWithMemoization, value);
}
Aggregations