public static String[] parseAsCsv(String key, String value, Function<String, String> valueProcessor) { String cleanValue = MultivalueProperty.trimFieldsAndRemoveEmptyFields(value); List<String> result = new ArrayList<>(); try (CSVParser csvParser = CSVFormat.RFC4180 .withHeader((String) null) .withIgnoreEmptyLines() .withIgnoreSurroundingSpaces() .parse(new StringReader(cleanValue))) { List<CSVRecord> records = csvParser.getRecords(); if (records.isEmpty()) { return ArrayUtils.EMPTY_STRING_ARRAY; } processRecords(result, records, valueProcessor); return result.toArray(new String[result.size()]); } catch (IOException e) { throw new IllegalStateException("Property: '" + key + "' doesn't contain a valid CSV value: '" + value + "'", e); } }
/** * Returns a new {@code CSVFormat} with the empty line skipping behavior of the format set to {@code true}. * * @return A new CSVFormat that is equal to this but with the specified empty line skipping behavior. * @since {@link #withIgnoreEmptyLines(boolean)} * @since 1.1 */ public CSVFormat withIgnoreEmptyLines() { return this.withIgnoreEmptyLines(true); }
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); }
CSVFormat format = CSVFormat.newFormat(valueSeparator) .withAllowMissingColumnNames() .withIgnoreEmptyLines();
.withIgnoreEmptyLines(true) .withDelimiter(asControlCharacter(fieldDelimiter)) .withQuote(asControlCharacter(quoteCharacter));
/** * Returns a new {@code CSVFormat} with the empty line skipping behavior of the format set to {@code true}. * * @return A new CSVFormat that is equal to this but with the specified empty line skipping behavior. * @since {@link #withIgnoreEmptyLines(boolean)} * @since 1.1 */ public CSVFormat withIgnoreEmptyLines() { return this.withIgnoreEmptyLines(true); }
/** * Returns a new {@code CSVFormat} with the empty line skipping behavior of the format set to {@code true}. * * @return A new CSVFormat that is equal to this but with the specified empty line skipping behavior. * @since {@link #withIgnoreEmptyLines(boolean)} * @since 1.1 */ public CSVFormat withIgnoreEmptyLines() { return this.withIgnoreEmptyLines(true); }
/** * Sets the empty line skipping behavior of the format to {@code true}. * * @return A new CSVFormat that is equal to this but with the specified empty line skipping behavior. * @since {@link #withIgnoreEmptyLines(boolean)} * @since 1.1 */ public CSVFormat withIgnoreEmptyLines() { return this.withIgnoreEmptyLines(true); }
final String[] option_parts = option.split("=", 2); if ("IgnoreEmpty".equalsIgnoreCase(option_parts[0])) { format = format.withIgnoreEmptyLines(Boolean.parseBoolean(option_parts[1])); } else if ("IgnoreSpaces".equalsIgnoreCase(option_parts[0])) { format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1]));
final String[] option_parts = option.split("=", 2); if ("IgnoreEmpty".equalsIgnoreCase(option_parts[0])) { format = format.withIgnoreEmptyLines(Boolean.parseBoolean(option_parts[1])); } else if ("IgnoreSpaces".equalsIgnoreCase(option_parts[0])) { format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1]));
.withFirstRecordAsHeader() .withIgnoreHeaderCase() .withIgnoreEmptyLines() .withTrim()); ) {
format = format.withHeaderComments("headerComment"); format = format.withNullString("NULL"); format = format.withIgnoreEmptyLines(true); format = format.withIgnoreSurroundingSpaces(true); format = format.withQuote('"');
CsvLineParser(char fieldDelimiter, char quote, char escape) { this.csvFormat = CSVFormat.DEFAULT .withIgnoreEmptyLines(true) .withDelimiter(fieldDelimiter) .withEscape(escape) .withQuote(quote); }
private static CSVParser readCsvRecords(List<String> header, String content) { try { CSVFormat csvFormat = CSVFormat.RFC4180; if (header.isEmpty()) { csvFormat = csvFormat.withFirstRecordAsHeader(); } return csvFormat. withIgnoreSurroundingSpaces(). withIgnoreEmptyLines(). withTrim(). withDelimiter(','). parse(new StringReader(content)); } catch (IOException e) { throw new RuntimeException(e); } }
CsvLineParser(char fieldDelimiter, char quote, char escape) { this.csvFormat = CSVFormat.DEFAULT .withIgnoreEmptyLines(true) .withDelimiter(fieldDelimiter) .withEscape(escape) .withQuote(quote); }
private static CSVParser readCsvRecords(List<String> header, String content) { try { CSVFormat csvFormat = CSVFormat.RFC4180; if (header.isEmpty()) { csvFormat = csvFormat.withFirstRecordAsHeader(); } return csvFormat. withIgnoreSurroundingSpaces(). withIgnoreEmptyLines(). withTrim(). withDelimiter(','). parse(new StringReader(content)); } catch (IOException e) { throw new RuntimeException(e); } }
private CSVParser createCSVParser(CSVParserSettings parserSettings) { CSVFormat csvFormat = CSVFormat.DEFAULT.withDelimiter(parserSettings.getDelimiter()) .withRecordSeparator(parserSettings.getRecordSeparator()) .withTrim(parserSettings.isTrim()) .withQuote(parserSettings.getQuote()) .withCommentMarker(parserSettings.getCommentMarker()) .withIgnoreEmptyLines(parserSettings.isIgnoreEmptyLines()) .withNullString(parserSettings.getNullString()); try { File file = new File(parserSettings.getPath()); return new CSVParser(new FileReader(file), csvFormat); } catch (Exception e) { throw e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e); } } }
private CSVParser createCSVParser(CSVParserSettings parserSettings) { CSVFormat csvFormat = CSVFormat.DEFAULT.withDelimiter(parserSettings.getDelimiter()) .withRecordSeparator(parserSettings.getRecordSeparator()) .withTrim(parserSettings.isTrim()) .withQuote(parserSettings.getQuote()) .withCommentMarker(parserSettings.getCommentMarker()) .withIgnoreEmptyLines(parserSettings.isIgnoreEmptyLines()) .withNullString(parserSettings.getNullString()); try { File file = new File(parserSettings.getPath()); return new CSVParser(new FileReader(file), csvFormat); } catch (Exception e) { throw e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e); } } }
private CSVParser getInternalParser(final Reader reader) { final CSVFormat csvFormat = CSVFormat.newFormat(columnSeparator).withQuote(quoteCharacter).withEscape(escapeCharacter) .withRecordSeparator(lineEnding).withIgnoreEmptyLines(true).withIgnoreSurroundingSpaces(true); try { return new CSVParser(reader, csvFormat); } catch (final IOException e) { throw new MetafactureException(e); } }