mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-15 09:21:06 +02:00
[ONOS-6892] Use streams for Kryo serialization to avoid IndexOutOfBoundsException when serializing/deserializing large objects
Change-Id: Ifc1ecf59f655aa65f034f94e10b61e77bbe4c3c4
This commit is contained in:
parent
a37e32f488
commit
ecfca4f877
@ -33,6 +33,8 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.objenesis.strategy.StdInstantiatorStrategy;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -303,11 +305,12 @@ public final class KryoNamespace implements KryoFactory, KryoPool {
|
||||
* @return serialized bytes
|
||||
*/
|
||||
public byte[] serialize(final Object obj, final int bufferSize) {
|
||||
Output out = new Output(bufferSize, MAX_BUFFER_SIZE);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(bufferSize);
|
||||
Output out = new Output(outputStream);
|
||||
return pool.run(kryo -> {
|
||||
kryo.writeClassAndObject(out, obj);
|
||||
out.flush();
|
||||
return out.toBytes();
|
||||
return outputStream.toByteArray();
|
||||
});
|
||||
}
|
||||
|
||||
@ -364,7 +367,7 @@ public final class KryoNamespace implements KryoFactory, KryoPool {
|
||||
* @return deserialized Object
|
||||
*/
|
||||
public <T> T deserialize(final byte[] bytes) {
|
||||
Input in = new Input(bytes);
|
||||
Input in = new Input(new ByteArrayInputStream(bytes));
|
||||
Kryo kryo = borrow();
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
Loading…
x
Reference in New Issue
Block a user