public int estimatePayloadSizeAfterAdding ( String propertyName , Object propertyValue ) { try { int maximumPayloadSize = getMaximumPayloadSize ( ) ; int currentPayloadSize = getPayloadAsBytesUnchecked ( ) . length ; int estimatedSize = currentPayloadSize ; if ( propertyName != null && propertyValue != null ) { estimatedSize += 5 ; // "":"" estimatedSize += propertyName . getBytes ( getCharacterEncoding ( ) ) . length ; int estimatedValueSize = 0 ; if ( propertyValue instanceof String || propertyValue instanceof Number ) estimatedValueSize = propertyValue . toString ( ) . getBytes ( getCharacterEncoding ( ) ) . length ; estimatedSize += estimatedValueSize ; } return estimatedSize ; } catch ( Exception e ) { try { return getPayloadSize ( ) ; } catch ( Exception e1 ) { return 0 ; } } }
Estimate the size that this payload will take after adding a given property . For performance reasons this estimate is not as reliable as actually adding the property and checking the payload size afterwards .