public void writeNext(String[] nextLine, boolean applyQuotesToAll) {

      if (nextLine == null) {
         return;
      }

      StringBuilder sb = new StringBuilder(nextLine.length * 2); // This is for the worse case where all elements have to be escaped.
      for (int i = 0; i < nextLine.length; i++) {

         if (i != 0) {
            sb.append(separator);
         }

         String nextElement = nextLine[i];

         if (nextElement == null) {
            continue;
         }

         Boolean stringContainsSpecialCharacters = stringContainsSpecialCharacters(nextElement);

         if ((applyQuotesToAll || stringContainsSpecialCharacters) && (quotechar != NO_QUOTE_CHARACTER)) {
            sb.append(quotechar);
         }

         if (stringContainsSpecialCharacters) {
            sb.append(processLine(nextElement));
         } else {
            sb.append(nextElement);
         }

         if ((applyQuotesToAll || stringContainsSpecialCharacters) && (quotechar != NO_QUOTE_CHARACTER)) {
            sb.append(quotechar);
         }
      }

      sb.append(lineEnd);
      pw.write(sb.toString());
   }
public void writeNext(String[] nextLine, boolean applyQuotesToAll) {

      if (nextLine == null) {
         return;
      }

      StringBuilder sb = new StringBuilder(nextLine.length * 2); 
      for (int i = 0; i < nextLine.length; i++) {

         if (i != 0) {
            sb.append(separator);
         }

         String nextElement = nextLine[i];

         if (nextElement == null) {
            continue;
         }

         Boolean stringContainsSpecialCharacters = stringContainsSpecialCharacters(nextElement);

         if ((applyQuotesToAll || stringContainsSpecialCharacters) && (quotechar != NO_QUOTE_CHARACTER)) {
            sb.append(quotechar);
         }

         if (stringContainsSpecialCharacters) {
            sb.append(processLine(nextElement));
         } else {
            sb.append(nextElement);
         }

         if ((applyQuotesToAll || stringContainsSpecialCharacters) && (quotechar != NO_QUOTE_CHARACTER)) {
            sb.append(quotechar);
         }
      }

      sb.append(lineEnd);
      pw.write(sb.toString());
   }
public void writeNext ( String [ ] nextLine , boolean applyQuotesToAll ) { if ( nextLine == null ) { return ; } StringBuilder sb = new StringBuilder ( nextLine . length * 2 ) ; // This is for the worse case where all elements have to be escaped. for ( int i = 0 ; i < nextLine . length ; i ++ ) { if ( i != 0 ) { sb . append ( separator ) ; } String nextElement = nextLine [ i ] ; if ( nextElement == null ) { continue ; } Boolean stringContainsSpecialCharacters = stringContainsSpecialCharacters ( nextElement ) ; if ( ( applyQuotesToAll || stringContainsSpecialCharacters ) && ( quotechar != NO_QUOTE_CHARACTER ) ) { sb . append ( quotechar ) ; } if ( stringContainsSpecialCharacters ) { sb . append ( processLine ( nextElement ) ) ; } else { sb . append ( nextElement ) ; } if ( ( applyQuotesToAll || stringContainsSpecialCharacters ) && ( quotechar != NO_QUOTE_CHARACTER ) ) { sb . append ( quotechar ) ; } } sb . append ( lineEnd ) ; pw . write ( sb . toString ( ) ) ; }
Writes the next line to the file.

@param nextLine         a string array with each comma-separated element as a separate
entry.
@param applyQuotesToAll true if all values are to be quoted.  false applies quotes only
to values which contain the separator, escape, quote or new line characters.
Writes the next line to the file .