com.esotericsoftware.kryo.pool.KryoCallback Java Examples

The following examples show how to use com.esotericsoftware.kryo.pool.KryoCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SerializeUtils.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static byte[] kryoSerialize(final Serializable obj) throws IOException {
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	final Output output = new Output(baos);

	try {
		kryoPool.run(new KryoCallback<Object>() {
			public Object execute(Kryo kryo) {
				kryo.writeClassAndObject(output, obj);
				return null;
			}
		});
	} finally {
		CommonUtils.closeQuietly(output);
	}

	return baos.toByteArray();
}
 
Example #2
Source File: KryoUtils.java    From kafka-examples with Apache License 2.0 5 votes vote down vote up
public static byte[] serialize(final Object obj) {

        return pool.run(new KryoCallback<byte[]>() {

            @Override
            public byte[] execute(Kryo kryo) {
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                Output output = new Output(stream);
                kryo.writeClassAndObject(output, obj);
                output.close();
                return stream.toByteArray();
            }

        });
    }
 
Example #3
Source File: KryoUtils.java    From kafka-examples with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <V> V deserialize(final byte[] objectData) {

    return (V) pool.run(new KryoCallback<V>() {

        @Override
        public V execute(Kryo kryo) {
            Input input = new Input(objectData);
            return (V) kryo.readClassAndObject(input);
        }

    });
}
 
Example #4
Source File: KryoUtils.java    From kafka-examples with Apache License 2.0 5 votes vote down vote up
public static <V> V deepCopy(final V obj) {

        return (V) pool.run(new KryoCallback<V>() {

            @Override
            public V execute(Kryo kryo) {
                return (V) kryo.copy(obj);
            }

        });
    }
 
Example #5
Source File: SerializeUtils.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Serializable kryoDeserialize(byte[] byteArray) throws IOException {
	final Input input = new Input(new ByteArrayInputStream(byteArray));

	try {
		return kryoPool.run(new KryoCallback<Serializable>() {
			public Serializable execute(Kryo kryo) {
				return (Serializable) kryo.readClassAndObject(input);
			}
		});
	} finally {
		CommonUtils.closeQuietly(input);
	}
}
 
Example #6
Source File: Namespace.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T run(KryoCallback<T> callback) {
  return kryoPool.run(callback);
}
 
Example #7
Source File: KryoNamespace.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T run(KryoCallback<T> callback) {
    return pool.run(callback);
}