Widely used (Spark, ...).
Kryo instances are not thread safe.
Serialization
Kryo kryo = new Kryo();ByteArrayOutputStream bos = new ByteArrayOutputStream();
Output output = new Output(bos);
byte bytes[];
try {
kryo.writeClassAndObject(output, obj);
bytes = output.toBytes();
} finally {
bos.close();
}
Deserialization
Kryo kryo = new Kryo();Input input = new Input(bytes);
Object obj;
try {
obj = kryo.readClassAndObject(input);
}
finally {
input.close();
}
finally {
input.close();
}
No comments:
Post a Comment