private void writeRowsToCSV ( List < String [ ] > rows ) throws BindException { int numBytes ; int rowNum = 0 ; int fileCount = 0 ; while ( rowNum < rows . size ( ) ) { File file = getFile ( ++ fileCount ) ; try ( OutputStream out = openFile ( file ) ) { // until we reach the last row or the file is too big, write to the file numBytes = 0 ; while ( numBytes < fileSize && rowNum < rows . size ( ) ) { byte [ ] csv = createCSVRecord ( rows . get ( rowNum ) ) ; numBytes += csv . length ; out . write ( csv ) ; rowNum ++ ; } } catch ( IOException ex ) { throw new BindException ( String . format ( "Exception encountered while writing to file: %s" , ex . getMessage ( ) ) , BindException . Type . SERIALIZATION ) ; } } }
Write the list of rows to compressed CSV files in the temporary directory