/** * Returns a new {@code CSVFormat} with the header ignore case behavior set to {@code true}. * * @return A new CSVFormat that will ignore case header name. * @see #withIgnoreHeaderCase(boolean) * @since 1.3 */ public CSVFormat withIgnoreHeaderCase() { return this.withIgnoreHeaderCase(true); }
/** * Returns a new {@code CSVFormat} with the header ignore case behavior set to {@code true}. * * @return A new CSVFormat that will ignore case header name. * @see #withIgnoreHeaderCase(boolean) * @since 1.3 */ public CSVFormat withIgnoreHeaderCase() { return this.withIgnoreHeaderCase(true); }
/** * Returns a new {@code CSVFormat} with the header ignore case behavior set to {@code true}. * * @return A new CSVFormat that will ignore case header name. * @see #withIgnoreHeaderCase(boolean) * @since 1.3 */ public CSVFormat withIgnoreHeaderCase() { return this.withIgnoreHeaderCase(true); }
.withHeader(Header.class) .withFirstRecordAsHeader() .withIgnoreHeaderCase() .withIgnoreEmptyLines() .withTrim());
@SuppressWarnings("deprecation") public MetadataFetcherCsv(DocIndexer docIndexer) { super(docIndexer); String metadataFileName = docIndexer.getParameter("metadataFile"); try ( Reader reader = new InputStreamReader(new BOMInputStream(new FileInputStream(metadataFileName)), "UTF-8"); CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT .withFirstRecordAsHeader() .withIgnoreHeaderCase() .withTrim()); ){ metadata = csvParser.getRecords(); reader.close(); } catch (FileNotFoundException ex) { System.err.println("Metadata file \""+metadataFileName+"\" not found. Not adding metadata."); } catch (IOException ex){ System.err.println("Error while reading \""+metadataFileName+"\". Is it a valid csv file?"); } }
public static CSVParser configureCSVParser(File file, Character fieldSeparator, Charset charset, boolean withFirstRecordAsHeader) throws IOException { if (fieldSeparator == null) { fieldSeparator = ','; } CSVFormat csvFormat = CSVFormat.DEFAULT .withDelimiter(fieldSeparator) .withIgnoreEmptyLines(true) .withNullString("") .withIgnoreSurroundingSpaces(true) .withTrim(true); if (withFirstRecordAsHeader) { csvFormat = csvFormat .withFirstRecordAsHeader() .withAllowMissingColumnNames(false) .withIgnoreHeaderCase(false); } else { csvFormat = csvFormat.withHeader((String[]) null).withSkipHeaderRecord(false); } FileInputStream fileInputStream = new FileInputStream(file); InputStreamReader is = new InputStreamReader(fileInputStream, charset); return new CSVParser(is, csvFormat); } }
answer = answer.withIgnoreHeaderCase(ignoreHeaderCase);