protected void writeRow ( final String ... columns ) throws IOException { if ( columns == null ) { throw new NullPointerException ( String . format ( "columns to write should not be null on line %d" , lineNumber ) ) ; } else if ( columns . length == 0 ) { throw new IllegalArgumentException ( String . format ( "columns to write should not be empty on line %d" , lineNumber ) ) ; } StringBuilder builder = new StringBuilder ( ) ; for ( int i = 0 ; i < columns . length ; i ++ ) { columnNumber = i + 1 ; // column no used by CsvEncoder if ( i > 0 ) { builder . append ( ( char ) preference . getDelimiterChar ( ) ) ; // delimiter } final String csvElement = columns [ i ] ; if ( csvElement != null ) { final CsvContext context = new CsvContext ( lineNumber , rowNumber , columnNumber ) ; final String escapedCsv = encoder . encode ( csvElement , context , preference ) ; builder . append ( escapedCsv ) ; lineNumber = context . getLineNumber ( ) ; // line number can increment when encoding multi-line columns } } builder . append ( preference . getEndOfLineSymbols ( ) ) ; // EOL writer . write ( builder . toString ( ) ) ; }
Writes one or more String columns as a line to the CsvWriter .