public PayloadBuilder resizeAlertBody ( final int payloadLength , final String postfix ) { int currLength = length ( ) ; if ( currLength <= payloadLength ) { return this ; } // now we are sure that truncation is required String body = ( String ) customAlert . get ( "body" ) ; final int acceptableSize = Utilities . toUTF8Bytes ( body ) . length - ( currLength - payloadLength + Utilities . toUTF8Bytes ( postfix ) . length ) ; body = Utilities . truncateWhenUTF8 ( body , acceptableSize ) + postfix ; // set it back customAlert . put ( "body" , body ) ; // calculate the length again currLength = length ( ) ; if ( currLength > payloadLength ) { // string is still too long, just remove the body as the body is // anyway not the cause OR the postfix might be too long customAlert . remove ( "body" ) ; } return this ; }
Shrinks the alert message body so that the resulting payload message fits within the passed expected payload length .