public static void appendString(final StringBuffer buf,final String s){
  buf.append('\"');
  for (int i=0; i < s.length(); ++i) {
    char c=s.charAt(i);
    if (c == '\n') {
      buf.append("\\n");
    }
 else     if (c == '\r') {
      buf.append("\\r");
    }
 else     if (c == '\\') {
      buf.append("\\\\");
    }
 else     if (c == '"') {
      buf.append("\\\"");
    }
 else     if (c < 0x20 || c > 0x7f) {
      buf.append("\\u");
      if (c < 0x10) {
        buf.append("000");
      }
 else       if (c < 0x100) {
        buf.append("00");
      }
 else       if (c < 0x1000) {
        buf.append('0');
      }
      buf.append(Integer.toString(c,16));
    }
 else {
      buf.append(c);
    }
  }
  buf.append('\"');
}

public static void appendString ( final StringBuffer buf , final String s ) { buf . append ( '\"' ) ; for ( int i = 0 ; i < s . length ( ) ; ++ i ) { char c = s . charAt ( i ) ; if ( c == '\n' ) { buf . append ( "\\n" ) ; } else if ( c == '\r' ) { buf . append ( "\\r" ) ; } else if ( c == '\\' ) { buf . append ( "\\\\" ) ; } else if ( c == '"' ) { buf . append ( "\\\"" ) ; } else if ( c < 0x20 || c > 0x7f ) { buf . append ( "\\u" ) ; if ( c < 0x10 ) { buf . append ( "000" ) ; } else if ( c < 0x100 ) { buf . append ( "00" ) ; } else if ( c < 0x1000 ) { buf . append ( '0' ) ; } buf . append ( Integer . toString ( c , 16 ) ) ; } else { buf . append ( c ) ; } } buf . append ( '\"' ) ; }
appends a quoted string to a given buffer .
