private static CSVFormat formatForDelimiter(char delimiter) { CSVFormat format = CSV_FORMAT; if (delimiter != format.getDelimiter()) { format = format.withDelimiter(delimiter); } return format; }
_format = CSVFormat.DEFAULT.withDelimiter(CSVRecordReaderConfig.DEFAULT_DELIMITER).withHeader(); _multiValueDelimiter = CSVRecordReaderConfig.DEFAULT_MULTI_VALUE_DELIMITER; } else { format = format.withDelimiter(delimiter); String csvHeader = config.getHeader(); if (csvHeader == null) {
.RFC4180 .withHeader() .withDelimiter(delimiter) .withQuote(quote) .withRecordSeparator(recordSeparator);
CsvLineParser(char fieldDelimiter, char quote, char escape) { this.csvFormat = CSVFormat.DEFAULT .withIgnoreEmptyLines(true) .withDelimiter(fieldDelimiter) .withEscape(escape) .withQuote(quote); }
CsvLineParser(char fieldDelimiter, char quote, char escape) { this.csvFormat = CSVFormat.DEFAULT.withIgnoreEmptyLines(true).withDelimiter(fieldDelimiter) .withEscape(escape).withQuote(quote); }
public CSVFormat getCSVFormat() { return CSVFormat.DEFAULT .withDelimiter(delimiter) .withRecordSeparator(recordSeparator) .withNullString(nullString) .withEscape(escapeCharacter) .withQuote(quoteCharacter) .withQuoteMode(quoteMode); }
@Test(expected = IllegalArgumentException.class) public void testInvalidFormat() throws Exception { final CSVFormat invalidFormat = CSVFormat.DEFAULT.withDelimiter(CR); try (final CSVPrinter printer = new CSVPrinter(new StringWriter(), invalidFormat)) { Assert.fail("This test should have thrown an exception."); } }
CSVFormat format = CSVFormat.DEFAULT .withIgnoreEmptyLines(true) .withDelimiter(asControlCharacter(fieldDelimiter)) .withQuote(asControlCharacter(quoteCharacter));
/** * Default: ';' * @param delimiter * @return */ public ImportConfigurationBuilder setDelimiter(char delimiter) { csvFormat = csvFormat.withDelimiter(delimiter); return this; }
public FormatCsvRecord2(char fieldDelimiter) { this.fieldDelimiter = fieldDelimiter; format = CSVFormat.RFC4180.withDelimiter(fieldDelimiter); }
private static CSVFormat formatForDelimiter(char delimiter) { CSVFormat format = CSV_FORMAT; if (delimiter != format.getDelimiter()) { format = format.withDelimiter(delimiter); } return format; }
public List<Tuple> read(InputStream is) throws IOException { CSVFormat format = CSVFormat.RFC4180.withHeader().withDelimiter(delim.charAt(0)); CSVParser csvParser = new CSVParser(new InputStreamReader(is), format); List<CSVRecord> records = csvParser.getRecords(); header = csvParser.getHeaderMap().entrySet().stream() .sorted((e1, e2) -> e1.getValue().compareTo(e2.getValue())) .map(Map.Entry::getKey).toArray(String[]::new); labelCol = labelCol == -1 ? records.get(0).size() - 1 : labelCol; List<Tuple> ds = records.stream().parallel().map(this::extractValuedFeat).collect(Collectors.toList()); return ds; }
@Override public void write(Map<String, String> line) throws IOException { if (csvPrinter == null) { headers = line.keySet().toArray(new String[line.size()]); csvPrinter = CSVFormat.DEFAULT.withDelimiter(delimiter).withHeader(headers).print(writer); } String[] values = new String[headers.length]; for (int i = 0; i < headers.length; i++) { values[i] = line.get(headers[i]); } csvPrinter.printRecord(values); }
@Override public void write(Map<String, Object> line) throws IOException { if (csvPrinter == null) { headers = line.keySet().toArray(new String[line.size()]); csvPrinter = CSVFormat.DEFAULT.withDelimiter(delimiter).withHeader(headers).print(writer); } Object[] values = new Object[headers.length]; for (int i = 0; i < headers.length; i++) { values[i] = line.get(headers[i]); } csvPrinter.printRecord(values); }
format = format.withDelimiter(','); format = format.withEscape('\\'); format = format.withHeader("author", "title", "publishDate");
@Override public Map<String, Object> next() throws IOException { if (csvParser == null) { csvParser = CSVFormat.DEFAULT.withHeader().withDelimiter(delimiter).parse(inputStream); iterator = csvParser.iterator(); } if (!iterator.hasNext()) { return null; } CSVRecord csvRecord = iterator.next(); return new HashMap<String, Object>(csvRecord.toMap()); }
@Override public Map<String, String> next() throws IOException { if (csvParser == null) { csvParser = CSVFormat.DEFAULT.withHeader().withDelimiter(delimiter).parse(inputStream); iterator = csvParser.iterator(); } if (!iterator.hasNext()) { return null; } CSVRecord csvRecord = iterator.next(); return csvRecord.toMap(); }
CsvLineParser(char fieldDelimiter, char quote, char escape) { this.csvFormat = CSVFormat.DEFAULT .withIgnoreEmptyLines(true) .withDelimiter(fieldDelimiter) .withEscape(escape) .withQuote(quote); }
private static CSVFormat getCSVStrategyFromConfiguration() { char fieldDelimiter = getCharValueFromConfiguration( "any23.extraction.csv.field", DEFAULT_FIELD_DELIMITER ); char commentDelimiter = getCharValueFromConfiguration( "any23.extraction.csv.comment", DEFAULT_COMMENT_DELIMITER ); return CSVFormat.DEFAULT.withDelimiter(fieldDelimiter).withCommentMarker(commentDelimiter); }
CsvLineParser(char fieldDelimiter, char quote, char escape) { this.csvFormat = CSVFormat.DEFAULT .withIgnoreEmptyLines(true) .withDelimiter(fieldDelimiter) .withEscape(escape) .withQuote(quote); }