@Override public byte[] objectToByteBuffer(Object obj, int estimatedSize) throws IOException, InterruptedException { ByteBuffer b = objectToBuffer(obj, estimatedSize); return trimBuffer(b); }
@Override public ByteBuffer objectToBuffer(Object obj) throws IOException, InterruptedException { if (obj != null) { BufferSizePredictor sizePredictor = marshallableTypeHints .getBufferSizePredictor(obj.getClass()); int estimatedSize = sizePredictor.nextSize(obj); 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); } }