private String normalizeWhitespace ( String payload ) { if ( ignoreWhitespace ) { StringBuilder result = new StringBuilder ( ) ; boolean lastWasSpace = true ; for ( int i = 0 ; i < payload . length ( ) ; i ++ ) { char c = payload . charAt ( i ) ; if ( Character . isWhitespace ( c ) ) { if ( ! lastWasSpace ) { result . append ( ' ' ) ; } lastWasSpace = true ; } else { result . append ( c ) ; lastWasSpace = false ; } } return result . toString ( ) . trim ( ) ; } if ( ignoreNewLineType ) { return payload . replaceAll ( "\\r(\\n)?" , "\n" ) ; } return payload ; }
Normalize whitespace characters if appropriate . Based on system property settings this method normalizes new line characters exclusively or filters all whitespaces such as double whitespaces and new lines .