public void appendValue(String str){
  appendDoubleQuote();
  byte[] data=str.getBytes(DEFAULT_CHARSET);
  int pos=0;
  for (int i=0; i < data.length; ++i) {
    int ch=data[i] & 0xFF;
    if ((ch < ' ') || (ch == '"') || (ch == '\\')) {
      append(data,pos,i - pos);
      pos=i + 1;
      if (ch == '\n') {
        append(NEWLINE);
      }
 else       if (ch == '\t') {
        append(HORIZONTAL_TAB);
      }
 else       if (ch == '\r') {
        append(CARRIAGE_RETURN);
      }
 else       if (ch < ' ') {
        append(UNICODE);
        int nibble=0xF000;
        int shift=12;
        for (int j=0; j < 4; ++j) {
          int xch=(ch & nibble) >> shift;
          if (xch < 10)           xch+='0';
 else           xch=(xch - 10) + 'A';
          hextmp[j]=(byte)xch;
          shift-=4;
          nibble>>=4;
        }
        append(hextmp);
      }
 else {
        append(BACKSLASH);
        --pos;
      }
    }
  }
  append(data,pos,data.length - pos);
  appendDoubleQuote();
}

public void appendValue ( String str ) { appendDoubleQuote ( ) ; byte [ ] data = str . getBytes ( DEFAULT_CHARSET ) ; int pos = 0 ; for ( int i = 0 ; i < data . length ; ++ i ) { int ch = data [ i ] & 0xFF ; if ( ( ch < ' ' ) || ( ch == '"' ) || ( ch == '\\' ) ) { append ( data , pos , i - pos ) ; pos = i + 1 ; if ( ch == '\n' ) { append ( NEWLINE ) ; } else if ( ch == '\t' ) { append ( HORIZONTAL_TAB ) ; } else if ( ch == '\r' ) { append ( CARRIAGE_RETURN ) ; } else if ( ch < ' ' ) { append ( UNICODE ) ; int nibble = 0xF000 ; int shift = 12 ; for ( int j = 0 ; j < 4 ; ++ j ) { int xch = ( ch & nibble ) > > shift ; if ( xch < 10 ) xch += '0' ; else xch = ( xch - 10 ) + 'A' ; hextmp [ j ] = ( byte ) xch ; shift -= 4 ; nibble >>= 4 ; } append ( hextmp ) ; } else { append ( BACKSLASH ) ; -- pos ; } } } append ( data , pos , data . length - pos ) ; appendDoubleQuote ( ) ; }
append a string adding surrounding double - quotes and doing any necessary escaping of control characters , double - quotes , and backslashes .
