question: public static void filterOutbound ( StringBuilder message ) { for ( int i = 0 ; i < message . length ( ) ; i ++ ) { char currentChar = message . charAt ( i ) ; if ( LEGAL_CHARACTERS . indexOf ( currentChar ) == - 1 ) { if ( currentChar > 256 ) { int charAsInt = currentChar ; String stringVersion = Integer . toString ( charAsInt , 16 ) ; String replacement = "&#x" + stringVersion + ";" ; message . replace ( i , i + 1 , replacement ) ; i += replacement . length ( ) - 1 ; } else { message . deleteCharAt ( i ) ; i -- ; } } } }
target:  Filters out illegal chars, and appends a \n to the passed in message. This also converts unicode chars into Maciejg format. See maciejgFormatToUnicode for more info.