本文整理汇总了Java中com.esotericsoftware.kryo.SerializationException类的典型用法代码示例。如果您正苦于以下问题:Java SerializationException类的具体用法?Java SerializationException怎么用?Java SerializationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializationException类属于com.esotericsoftware.kryo包,在下文中一共展示了SerializationException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeToBytes
import com.esotericsoftware.kryo.SerializationException; //导入依赖的package包/类
/**
* Encodes the given object using registered Kryo serializers. Provides explicit buffer overflow protection, but
* careful buffer sizing should be employed to reduce the need for this facility.
*
* @param o Object to encode.
*
* @return Encoded bytes.
*/
private byte[] encodeToBytes(final Object o) {
int factor = 1;
byte[] result = null;
ByteBuffer buffer = Kryo.getContext().getBuffer(bufferSize * factor);
while (result == null) {
try {
kryo.writeClassAndObject(buffer, o);
result = new byte[buffer.flip().limit()];
buffer.get(result);
} catch (final SerializationException e) {
Throwable rootCause = e;
while (rootCause.getCause() != null) {
rootCause = rootCause.getCause();
}
if (rootCause instanceof BufferOverflowException) {
buffer = ByteBuffer.allocate(bufferSize * ++factor);
logger.warn("Buffer overflow while encoding {}", o);
} else {
throw e;
}
}
}
return result;
}