ByteBuffer byteBuffer = objectToBuffer(obj, estimatedSize);
int length = byteBuffer.getLength();
// If the prediction is way off, then trim it
if (estimatedSize > (length * 4)) {
byte[] buffer = trimBuffer(byteBuffer);
byteBuffer = new ByteBufferImpl(buffer, 0, buffer.length);
}
sizePredictor.recordSize(length);
return byteBuffer;
} else {
return objectToBuffer(null, 1);