scray.common.serialization.JavaTraversableSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scray-client-jdbc Show documentation
Show all versions of scray-client-jdbc Show documentation
scray java code, which can be used from java and scala
The newest version!
package scray.common.serialization;
import java.util.Collection;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
abstract public class JavaTraversableSerializer> extends Serializer{
abstract public A newCollection();
@Override
public void write(Kryo kryo, Output output, A object) {
output.writeInt(object.size(), true);
for(T item: object) {
kryo.writeClassAndObject(output, item);
output.flush();
}
}
@SuppressWarnings("unchecked")
@Override
public A read(Kryo kryo, Input input, Class type) {
int size = input.readInt(true);
A collection = newCollection();
for(int i = 0; i < size; i ++) {
collection.add((T)kryo.readClassAndObject(input));
}
return collection;
}
}