Thanks for the patch. I have some comments on this patch. Looks like this patch creates a ByteArrayOutputStream with initial size of 64K - similarly for the AdaptiveReceiveBufferSizePredictorFactory. I think we should start with a smaller buffer - probably at 2K and set the max to 64K.
So this can be AdaptiveReceiveBufferSizePredictorFactory (2048, 2048, 65536) and the ByteArrayOutputStream can be created using the current code itself. When the message is received, the current code already sets the maxSize to the event size.
I think the only change required to the original code is to use AdaptiveReceiveBufferSizePredictorFactory, but created with smaller buffer values. We can maybe ask the user for hints through config on average event size, but I doubt it is necessary.