/** * Returns a new {@code CSVFormat} with the comment start marker of the format set to the specified character. * * Note that the comment start character is only recognized at the start of a line. * * @param commentMarker * the comment start marker * @return A new CSVFormat that is equal to this one but with the specified character as the comment start marker * @throws IllegalArgumentException * thrown if the specified character is a line break */ public CSVFormat withCommentMarker(final char commentMarker) { return withCommentMarker(Character.valueOf(commentMarker)); }
format = format.withCommentMarker(getChar(context, COMMENT_MARKER));
@Test public void testMultiLineComment() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentMarker('#'))) { printer.printComment("This is a comment\non multiple lines"); assertEquals("# This is a comment" + recordSeparator + "# on multiple lines" + recordSeparator, sw.toString()); } }
@Test public void testSingleLineComment() throws IOException { final StringWriter sw = new StringWriter(); try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentMarker('#'))) { printer.printComment("This is a comment"); assertEquals("# This is a comment" + recordSeparator, sw.toString()); } }
format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1])); } else if ("CommentStart".equalsIgnoreCase(option_parts[0])) { format = format.withCommentMarker(option_parts[1].charAt(0)); } else if ("CheckComments".equalsIgnoreCase(option_parts[0])) { checkComments = true;
format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1])); } else if ("CommentStart".equalsIgnoreCase(option_parts[0])) { format = format.withCommentMarker(option_parts[1].charAt(0)); } else if ("CheckComments".equalsIgnoreCase(option_parts[0])) { checkComments = true;
/** * Returns a new {@code CSVFormat} with the comment start marker of the format set to the specified character. * * Note that the comment start character is only recognized at the start of a line. * * @param commentMarker * the comment start marker * @return A new CSVFormat that is equal to this one but with the specified character as the comment start marker * @throws IllegalArgumentException * thrown if the specified character is a line break */ public CSVFormat withCommentMarker(final char commentMarker) { return withCommentMarker(Character.valueOf(commentMarker)); }
/** * Returns a new {@code CSVFormat} with the comment start marker of the format set to the specified character. * * Note that the comment start character is only recognized at the start of a line. * * @param commentMarker * the comment start marker * @return A new CSVFormat that is equal to this one but with the specified character as the comment start marker * @throws IllegalArgumentException * thrown if the specified character is a line break */ public CSVFormat withCommentMarker(final char commentMarker) { return withCommentMarker(Character.valueOf(commentMarker)); }
private CSVPrinter printWithHeaderComments(final StringWriter sw, final Date now, final CSVFormat baseFormat) throws IOException { CSVFormat format = baseFormat; // Use withHeaderComments first to test CSV-145 format = format.withHeaderComments("Generated by Apache Commons CSV 1.1", now); format = format.withCommentMarker('#'); format = format.withHeader("Col1", "Col2"); final CSVPrinter csvPrinter = format.print(sw); csvPrinter.printRecord("A", "B"); csvPrinter.printRecord("C", "D"); csvPrinter.close(); return csvPrinter; }
/** * Sets the comment start marker of the format to the specified character. * * Note that the comment start character is only recognized at the start of a line. * * @param commentMarker * the comment start marker * @return A new CSVFormat that is equal to this one but with the specified character as the comment start marker * @throws IllegalArgumentException * thrown if the specified character is a line break */ public CSVFormat withCommentMarker(final char commentMarker) { return withCommentMarker(Character.valueOf(commentMarker)); }
public static List<Intersection> readIntersections(String fileName) { List<Intersection> intersections = new ArrayList<Intersection>(); try { Reader in = new BufferedReader(new InputStreamReader( new FileInputStream(fileName), "UTF-8")); CSVFormat formatter = CSVFormat.DEFAULT.withHeader(). withCommentMarker('-'); // Parse the file Iterable<CSVRecord> records = formatter.parse(in); Iterator<CSVRecord> iterator = records.iterator(); while (iterator.hasNext()) { // Determine the record to process CSVRecord record = iterator.next(); Intersection i = getIntersection(record); intersections.add(i); } } catch (Exception e) { e.printStackTrace(); } return intersections; }
@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.withCommentMarker('#'); format = format.withDelimiter(','); format = format.withEscape('\\');
@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('#'); }
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); }
public CSVEncoder() { final char escapeCharacter = '\\'; final char quoteCharacter = '"'; final char columnSeparator = ';'; final String lineEnding = System.getProperty("line.separator"); csvFormat = CSVFormat.newFormat(columnSeparator).withCommentMarker('#').withQuote(quoteCharacter).withEscape(escapeCharacter) .withRecordSeparator(lineEnding); }
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); } } }
public static void assertLabels(File labelFile, org.apache.samoa.TestParams testParams) throws IOException { LOG.info("Checking labels file " + labelFile.getAbsolutePath()); //1. parse result file with csv parser Reader in = new FileReader(labelFile); long lineCount = 0; long expectedLineCount = testParams.getInputInstances() / testParams.getLabelSamplingSize(); Iterable<CSVRecord> records = CSVFormat.EXCEL.withSkipHeaderRecord(false) .withIgnoreEmptyLines(true).withDelimiter(',').withCommentMarker('#').parse(in); Iterator<CSVRecord> iterator = records.iterator(); CSVRecord header = iterator.next(); while (iterator.hasNext()) { iterator.next(); lineCount = lineCount + 1; } Assert.assertEquals("Unexpected column", org.apache.samoa.TestParams.INSTANCE_ID, header.get(0).trim()); Assert.assertEquals("Unexpected column", org.apache.samoa.TestParams.TRUE_CLASS_VALUE, header.get(1).trim()); Assert.assertEquals("Unexpected column", org.apache.samoa.TestParams.PREDICTED_CLASS_VALUE, header.get(2).trim()); for (int i = 3; i < header.size(); i++) Assert.assertEquals("Unexpected column", org.apache.samoa.TestParams.VOTES, header.get(i).trim().substring(0, org.apache.samoa.TestParams.VOTES.length())); Assert.assertEquals("Wrong number of lines in prediction file", expectedLineCount, lineCount); }
public CSVFormat build() { CSVFormat format = newFormat(delimiter = initDelimiter()); format = format.withEscape(escape = initEscape()); format = format.withCommentMarker(commentMarker = initCommentMarker()); format = format.withRecordSeparator(lineSeparator = initLineSeparator()); quote = initQuote(); quoting = initQuoting(); if (quoting) { format = format.withQuoteMode(QuoteMode.MINIMAL); format = format.withQuote(quote); } return format; }