.withDelimiter(delimiter) .withQuote(quote) .withRecordSeparator(recordSeparator);
/** * Returns a new {@code CSVFormat} with the record separator of the format set to the operating system's line * separator string, typically CR+LF on Windows and LF on Linux. * * <p> * <strong>Note:</strong> This setting is only used during printing and does not affect parsing. Parsing currently * only works for inputs with '\n', '\r' and "\r\n" * </p> * * @return A new CSVFormat that is equal to this but with the operating system's line separator string. * @since 1.6 */ public CSVFormat withSystemRecordSeparator() { return withRecordSeparator(System.getProperty("line.separator")); }
/** * Returns a new {@code CSVFormat} with the record separator of the format set to the specified character. * * <p> * <strong>Note:</strong> This setting is only used during printing and does not affect parsing. Parsing currently * only works for inputs with '\n', '\r' and "\r\n" * </p> * * @param recordSeparator * the record separator to use for output. * * @return A new CSVFormat that is equal to this but with the specified output record separator */ public CSVFormat withRecordSeparator(final char recordSeparator) { return withRecordSeparator(String.valueOf(recordSeparator)); }
CSVFormat .DEFAULT .withRecordSeparator("\n") .withHeader(Header.class) .withQuoteMode(QuoteMode.ALL));
if (recordSeparator != null) { final String separator = unescape(recordSeparator.getValue()); format = format.withRecordSeparator(separator);
public CSVFormat getCSVFormat() { return CSVFormat.DEFAULT .withDelimiter(delimiter) .withRecordSeparator(recordSeparator) .withNullString(nullString) .withEscape(escapeCharacter) .withQuote(quoteCharacter) .withQuoteMode(quoteMode); }
@Test @Ignore public void testJira135All() throws IOException { final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH); final StringWriter sw = new StringWriter(); final List<String> list = new LinkedList<>(); try (final CSVPrinter printer = new CSVPrinter(sw, format)) { list.add("\""); list.add("\n"); list.add("\\"); printer.printRecord(list); } final String expected = "\"\\\"\",\"\\n\",\"\\\"" + format.getRecordSeparator(); assertEquals(expected, sw.toString()); final String[] record0 = toFirstRecordValues(expected, format); assertArrayEquals(expectNulls(list.toArray(), format), record0); }
@Test @Ignore public void testJira135_part2() throws IOException { final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH); final StringWriter sw = new StringWriter(); final List<String> list = new LinkedList<>(); try (final CSVPrinter printer = new CSVPrinter(sw, format)) { list.add("\n"); printer.printRecord(list); } final String expected = "\"\\n\"" + format.getRecordSeparator(); assertEquals(expected, sw.toString()); final String[] record0 = toFirstRecordValues(expected, format); assertArrayEquals(expectNulls(list.toArray(), format), record0); }
@Test @Ignore public void testJira135_part3() throws IOException { final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH); final StringWriter sw = new StringWriter(); final List<String> list = new LinkedList<>(); try (final CSVPrinter printer = new CSVPrinter(sw, format)) { list.add("\\"); printer.printRecord(list); } final String expected = "\"\\\\\"" + format.getRecordSeparator(); assertEquals(expected, sw.toString()); final String[] record0 = toFirstRecordValues(expected, format); assertArrayEquals(expectNulls(list.toArray(), format), record0); }
@Test @Ignore public void testJira135_part1() throws IOException { final CSVFormat format = CSVFormat.DEFAULT.withRecordSeparator('\n').withQuote(DQUOTE_CHAR).withEscape(BACKSLASH_CH); final StringWriter sw = new StringWriter(); final List<String> list = new LinkedList<>(); try (final CSVPrinter printer = new CSVPrinter(sw, format)) { list.add("\""); printer.printRecord(list); } final String expected = "\"\\\"\"" + format.getRecordSeparator(); assertEquals(expected, sw.toString()); final String[] record0 = toFirstRecordValues(expected, format); assertArrayEquals(expectNulls(list.toArray(), format), record0); }
CSVFormat .DEFAULT .withRecordSeparator("\n") .withHeader(Header.class) .withFirstRecordAsHeader()
public CsvDataLogger(Context context, File file) { this.context = context; this.file = file; CSVFormat csvFileFormat = CSVFormat.DEFAULT.withRecordSeparator(System.getProperty("line.separator")); try { fileWriter = new FileWriter(file); csv = new CSVPrinter(fileWriter, csvFileFormat); } catch (IOException e) { e.printStackTrace(); } headersSet = false; }
format = format.withQuote('"'); format = format.withQuoteMode(QuoteMode.ALL); format = format.withRecordSeparator('\n'); format = format.withSkipHeaderRecord(false);
/** * Create IS24-CSV format. */ public Is24CsvFormat() { super(CSVFormat.newFormat('|') .withRecordSeparator(RECORD_SEPARATOR) .withNullString(StringUtils.EMPTY)); }
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); }
/** * Returns the standard CSV format used by Obevo by both readers (for deploy) and writers (for reverse-engineering) of CSV. */ public static CSVFormat getCsvFormat(char delim, String nullToken) { return CSVFormat.newFormat(delim).withRecordSeparator("\r\n").withIgnoreSurroundingSpaces(true).withQuote('"').withEscape('\\').withNullString(nullToken); }
/** * Returns the standard CSV format used by Obevo by both readers (for deploy) and writers (for reverse-engineering) of CSV. */ public static CSVFormat getCsvFormat(char delim, String nullToken) { return CSVFormat.newFormat(delim).withRecordSeparator("\r\n").withIgnoreSurroundingSpaces(true).withQuote('"').withEscape('\\').withNullString(nullToken); }
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); } }
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; }