private static String escapeString(String str){
  int strLen=str.length();
  StringBuilder b=new StringBuilder(strLen);
  for (int i=0; i < strLen; i++) {
    char original=str.charAt(i);
    if (original >= ' ' && original <= '~' && original != '"' && original != '\'') {
      b.append(original);
    }
 else {
      b.append(String.format("\\u%04x",(int)original));
    }
  }
  return b.toString();
}

private static String escapeString ( String str ) { int strLen = str . length ( ) ; StringBuilder b = new StringBuilder ( strLen ) ; for ( int i = 0 ; i < strLen ; i ++ ) { char original = str . charAt ( i ) ; if ( original >= ' ' && original <= '~' && original != '"' && original != '\'' ) { b . append ( original ) ; } else { b . append ( String . format ( "\\u%04x" , ( int ) original ) ) ; } } return b . toString ( ) ; }
escape everything except for low ascii code points .
