ThanksShay
Your line is wrong, because it returns only the current content of the buffer, not everything you've ever written to it:buffer = output.getBuffer();
You should do:ByteArrayOutputStream baos = new ByteArrayOutputStream();Output output = new Output(baos);...output.close();buffer = baos.toByteArray();
--
You received this message because you are subscribed to the "kryo-users" group.
http://groups.google.com/group/kryo-users
---
You received this message because you are subscribed to the Google Groups "kryo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kryo-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks! Is these better:
public byte[] serialize(Object attribute) {
byte[] buffer = null;
init();
ByteArrayOutputStream bois = new ByteArrayOutputStream();
Output output = new Output(bois);
try {
try {
Kryo kryo = ser.get();
kryo.writeClassAndObject(output, attribute);
output.flush();
bois.flush();
buffer = bois.toByteArray();
} finally {
output.close();
bois.close();
}
} catch (IOException e) {
LOG.error("can not serialize class " + attribute, e);
throw new HttpSessionSerializationException(
"can not serialize class " + attribute, e);
}
return buffer;
}
public Object deserialize(byte[] buffer) {
Object result = null;
init();
Input input = new Input(buffer);
try {
Kryo kryo = ser.get();
result = kryo.readClassAndObject(input);
} finally {
input.close();
}
return result;
}