Search in sources :

Example 1 with ByteBuffer

use of org.infinispan.commons.io.ByteBuffer in project wildfly by wildfly.

the class AbstractMarshaller method objectToBuffer.

@Override
public ByteBuffer objectToBuffer(Object object) throws IOException {
    if (object == null) {
        return this.objectToBuffer(null, 1);
    }
    int estimatedSize = this.sizeEstimate(object);
    ByteBuffer buffer = this.objectToBuffer(object, estimatedSize);
    int actualSize = buffer.getLength() - Byte.BYTES;
    // If the prediction is way off, then trim it
    if (estimatedSize > (actualSize * 4)) {
        byte[] bytes = trim(buffer);
        buffer = ByteBufferImpl.create(bytes);
    }
    this.getBufferSizePredictor(object).recordSize(actualSize);
    return buffer;
}
Also used : ByteBuffer(org.infinispan.commons.io.ByteBuffer)

Aggregations

ByteBuffer (org.infinispan.commons.io.ByteBuffer)1