/** * Custodial tasks that must be performed before beans are written to a CSV * destination for the first time. * @param bean Any bean to be written. Used to determine the mapping * strategy automatically. The bean itself is not written to the output by * this method. * @throws CsvRequiredFieldEmptyException If a required header is missing * while attempting to write. Since every other header is hard-wired * through the bean fields and their associated annotations, this can only * happen with multi-valued fields. */ private void beforeFirstWrite(T bean) throws CsvRequiredFieldEmptyException { // Determine mapping strategy if(mappingStrategy == null) { mappingStrategy = OpencsvUtils.<T>determineMappingStrategy((Class<T>)bean.getClass(), errorLocale); } // Build CSVWriter if (csvwriter == null) { csvwriter = new CSVWriter(writer, separator, quotechar, escapechar, lineEnd); } // Write the header String[] header = mappingStrategy.generateHeader(bean); if(header.length > 0) { csvwriter.writeNext(header, applyQuotesToAll); } headerWritten = true; }
mappingStrategy = OpencsvUtils.determineMappingStrategy(type, errorLocale);