The following are top voted examples for showing how to use com.esotericsoftware.kryo.pool.KryoPool. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.
+ Save this class to your library
Example 1
Project: ecgine File: SerializationUtil.java View source code | 7 votes | ![]() ![]() |
public static byte[] kryoSerialize(Object obj) throws Exception { Output output = null; try { KryoPool pool = getKryoPool(); Kryo kryo = pool.borrow(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); output = new Output(bos); if (obj instanceof ARefType) { kryo.writeObject(output, obj, new FieldSerializer(kryo, obj.getClass())); } else { kryo.writeClassAndObject(output, obj); } output.flush(); byte[] data = bos.toByteArray(); output.close(); pool.release(kryo); // Serializable last = deserialize(data); return data; } catch (Exception e) { throw e; } finally { output.close(); } }
Example 2
Project: reactor File: KryoPoolCodec.java View source code | 6 votes | ![]() ![]() |
@Override protected Function<byte[], IN> deserializer(final KryoPool engine, final Class<IN> type) { return new Function<byte[], IN>() { @Override public IN apply(byte[] bytes) { final Kryo kryo = engine.borrow(); try { return kryo.readObject(new UnsafeMemoryInput(bytes), type); } finally { engine.release(kryo); } } }; }
Example 3
Project: reactor File: KryoPoolCodec.java View source code | 6 votes | ![]() ![]() |
@Override protected Function<OUT, byte[]> serializer(final KryoPool engine) { return new Function<OUT, byte[]>() { @Override public byte[] apply(OUT o) { final Kryo kryo = engine.borrow(); try { UnsafeMemoryOutput out = new UnsafeMemoryOutput(Buffer.SMALL_BUFFER_SIZE, Buffer.MAX_BUFFER_SIZE); kryo.writeObject(out, o); out.flush(); return out.toBytes(); } finally { engine.release(kryo); } } }; }
Example 4
Project: ecgine File: SerializationUtil.java View source code | 6 votes | ![]() ![]() |
public static KryoSerializable kryoDeserialize(InputStream bis) throws Exception { if (bis.available() <= 0) { return null; } try { KryoPool pool = getKryoPool(); Kryo kryo = pool.borrow(); Input input = new Input(bis); KryoSerializable opt = (KryoSerializable) kryo .readClassAndObject(input); input.close(); pool.release(kryo); return opt; } finally { bis.close(); } }
Example 5
Project: ratpack-examples File: KryoValueSerializer.java View source code | 6 votes | ![]() ![]() |
public ByteBuf serialize(Registry registry, ByteBufAllocator bufAllocator, Object value) throws Exception { Objects.requireNonNull(value); KryoPool kryoPool = registry.get(KryoPool.class); Kryo kryo = kryoPool.borrow(); try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); Output output = new Output(stream); kryo.writeClassAndObject(output, value); output.close(); byte[] bytes = stream.toByteArray(); String encoded = ENCODER.encodeToString(bytes); return ByteBufUtil.encodeString(bufAllocator, CharBuffer.wrap(encoded), CharsetUtil.UTF_8); } catch (Exception ex) { throw ex; } finally { kryoPool.release(kryo); } }
Example 6
Project: ratpack-examples File: KryoValueSerializer.java View source code | 6 votes | ![]() ![]() |
public Object deserialize(Registry registry, String value) throws Exception { if (value == null || value.isEmpty()) { return null; } KryoPool kryoPool = registry.get(KryoPool.class); Kryo kryo = kryoPool.borrow(); try { byte[] bytes = DECODER.decode(value); ByteArrayInputStream stream = new ByteArrayInputStream(bytes); Input input = new Input(stream); Object obj = kryo.readClassAndObject(input); input.close(); return obj; } catch (Exception ex) { throw ex; } finally { kryoPool.release(kryo); } }
https://www.programcreek.com/java-api-examples/index.php?api=com.esotericsoftware.kryo.pool.KryoPool