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--;
      }
    }
  }
}

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 -- ; } } } }
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 .
