/** * Returns a new {@code CSVFormat} with the missing column names behavior of the format set to {@code true} * * @return A new CSVFormat that is equal to this but with the specified missing column names behavior. * @see #withAllowMissingColumnNames(boolean) * @since 1.1 */ public CSVFormat withAllowMissingColumnNames() { return this.withAllowMissingColumnNames(true); }
private static CSVFormat buildCustomFormat(final PropertyContext context) { final char valueSeparator = getUnescapedChar(context, VALUE_SEPARATOR); CSVFormat format = CSVFormat.newFormat(valueSeparator) .withAllowMissingColumnNames() .withIgnoreEmptyLines();
/** * Sets the missing column names behavior of the format to {@code true} * * @return A new CSVFormat that is equal to this but with the specified missing column names behavior. * @see #withAllowMissingColumnNames(boolean) * @since 1.1 */ public CSVFormat withAllowMissingColumnNames() { return this.withAllowMissingColumnNames(true); }
/** * Returns a new {@code CSVFormat} with the missing column names behavior of the format set to {@code true} * * @return A new CSVFormat that is equal to this but with the specified missing column names behavior. * @see #withAllowMissingColumnNames(boolean) * @since 1.1 */ public CSVFormat withAllowMissingColumnNames() { return this.withAllowMissingColumnNames(true); }
/** * Returns a new {@code CSVFormat} with the missing column names behavior of the format set to {@code true} * * @return A new CSVFormat that is equal to this but with the specified missing column names behavior. * @see #withAllowMissingColumnNames(boolean) * @since 1.1 */ public CSVFormat withAllowMissingColumnNames() { return this.withAllowMissingColumnNames(true); }
@Override protected CSVFormat setupCSVParser(Vocabulary vocabulary) { // Bug in commons-csv: although duplicate null headers are allowed in CSVParser, CSVFormat#validate doesn't // allow more than one null header return CSVFormat.TDF.withHeader("id", null, "", "associated_genes").withAllowMissingColumnNames() .withCommentMarker('#'); } }
format = format.withAllowMissingColumnNames(false); format = format.withCommentMarker('#'); format = format.withDelimiter(',');
@Override protected CSVFormat setupCSVParser(Vocabulary vocabulary) { // Bug in commons-csv: although duplicate null headers are allowed in CSVParser, CSVFormat#validate doesn't // allow more than one null header return CSVFormat.TDF.withHeader("id", null, "", "associated_genes").withAllowMissingColumnNames() .withCommentMarker('#'); }
/** * Parses a sample file to allow schema specification when creating a new feed. * * @param sampleText the sample text * @return A configured parser * @throws IOException If there is an error parsing the sample file */ public CSVFormat detectCSVFormat(String sampleText, boolean headerRow, String seperatorStr) throws IOException { CSVFormat format = CSVFormat.DEFAULT.withAllowMissingColumnNames(); Character separatorChar = null; if (StringUtils.isNotBlank(seperatorStr)) { separatorChar = seperatorStr.charAt(0); } try (BufferedReader br = new BufferedReader(new StringReader(sampleText))) { List<LineStats> lineStats = generateStats(br, separatorChar); Character quote = guessQuote(lineStats); Character delim = guessDelimiter(lineStats, sampleText, quote, headerRow); if (delim == null) { throw new IOException("Unrecognized format"); } format = format.withDelimiter(delim); format = format.withQuoteMode(QuoteMode.MINIMAL).withQuote(quote); } return format; }
.withAllowMissingColumnNames() .withHeader();
/** * * @param delimiter * @param encapsulator * @param ignoreSurroundingSpaces * @param ignoreEmptyLines * @return */ public static CSVFormat getFormat(char delimiter, Character encapsulator, boolean ignoreSurroundingSpaces, boolean ignoreEmptyLines) { CSVFormat format = CSVFormat.newFormat(delimiter); format = format.withIgnoreEmptyLines(ignoreEmptyLines) .withIgnoreSurroundingSpaces(ignoreSurroundingSpaces) .withAllowMissingColumnNames(true) .withQuote(encapsulator); return format; } }
out = out.withAllowMissingColumnNames(Boolean.parseBoolean(allowMissingColumnNames));
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); } }
@Override public void initialize(Arguments args) throws DirectiveParseException { columnArg = args.value("col"); char delimiter = ','; if (args.contains("delimiter")) { delimiterArg = args.value("delimiter"); delimiter = delimiterArg.value().charAt(0); if (delimiterArg.value().startsWith("\\")) { String unescapedStr = StringEscapeUtils.unescapeJava(delimiterArg.value()); if (unescapedStr == null) { throw new DirectiveParseException("Invalid delimiter for CSV Parser: " + delimiterArg.value()); } delimiter = unescapedStr.charAt(0); } } this.format = CSVFormat.DEFAULT.withDelimiter(delimiter); this.format.withIgnoreEmptyLines(true) .withAllowMissingColumnNames(true) .withIgnoreSurroundingSpaces(true) .withRecordSeparator('\n'); this.hasHeader = false; if(args.contains("header")) { headerArg = args.value("header"); this.hasHeader = headerArg.value(); } }
answer = answer.withAllowMissingColumnNames(allowMissingColumnNames);
private static CSVFormat buildCustomFormat(final PropertyContext context) { final char valueSeparator = getUnescapedChar(context, VALUE_SEPARATOR); CSVFormat format = CSVFormat.newFormat(valueSeparator) .withAllowMissingColumnNames() .withIgnoreEmptyLines();