private static CSVFormat buildCustomFormat(final PropertyContext context) { final char valueSeparator = getUnescapedChar(context, VALUE_SEPARATOR); CSVFormat format = CSVFormat.newFormat(valueSeparator) .withAllowMissingColumnNames() .withIgnoreEmptyLines();
CSVFormat format = CSVFormat.newFormat(theDelimiter).withFirstRecordAsHeader(); if (theQuoteMode != null) { format = format.withQuote('"').withQuoteMode(theQuoteMode);
assertTrue(testName + " require 1 param", split.length >= 1); CSVFormat format = CSVFormat.newFormat(',').withQuote('"'); boolean checkComments = false; for (int i = 1; i < split.length; i++) {
assertTrue(testName + " require 1 param", split.length >= 1); CSVFormat format = CSVFormat.newFormat(',').withQuote('"'); boolean checkComments = false; for (int i = 1; i < split.length; i++) {
@Deprecated public Iterable<CSVRecord> getCells(String ruleStr, int firstNLineAsSetting) { settings = new LinkedHashMap<>(); Iterable<CSVRecord> recordsIterator = null; String extensionName = ruleStr.substring(ruleStr.length() - 5).toLowerCase(); if (extensionName.endsWith(".csv") || extensionName.endsWith(".tsv")) { try { ruleStr = FileUtils.readFileToString(new File(ruleStr)); } catch (IOException e) { e.printStackTrace(); } } int begin = readFirstNLines(ruleStr, firstNLineAsSetting, settings); // System.out.println(ruleStr.substring(0, begin)); String splitterStr = settings.get("splitter:"); splitter = splitterStr == null || splitterStr.length() == 0 ? '\t' : splitterStr.charAt(0); try { recordsIterator = CSVParser.parse(ruleStr.substring(begin), CSVFormat.newFormat(splitter)); } catch (IOException e) { e.printStackTrace(); } return recordsIterator; }
/** * Create IS24-CSV format. */ public Is24CsvFormat() { super(CSVFormat.newFormat('|') .withRecordSeparator(RECORD_SEPARATOR) .withNullString(StringUtils.EMPTY)); }
public static CSVParser readFileCSV(String basename, String... searchPaths) { Reader reader = findRequiredReader(basename, "csv", searchPaths); CSVFormat format = CSVFormat.newFormat(',').withFirstRecordAsHeader(); try { CSVParser parser = new CSVParser(reader, format); return parser; } catch (IOException e) { throw new RuntimeException(e); } }
private final static void write(final Path base, final RecordedDataStorage timeSeries, final DumpConfiguration config) { final String fileName; try { fileName = URLEncoder.encode(timeSeries.getPath(), StandardCharsets.UTF_8.toString()) + ".csv"; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } final Path target = base.resolve(fileName); final char delimiter = config.getDelimiter(); // TODO implement JSON and XML serialization final CSVFormat format = CSVFormat.newFormat(delimiter).withTrailingDelimiter(false).withRecordSeparator('\n'); try (final BufferedWriter writer = Files.newBufferedWriter(target); final CSVPrinter printer = new CSVPrinter(writer, format);) { SerializerImpl.write(timeSeries, config, printer); } catch (IOException e) { throw new UncheckedIOException(e); } }
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 static void zip(final CloseableDataRecorder instance, final Stream<FendoTimeSeries> stream, final DumpConfiguration config, final OutputStream out) throws IOException { final char delimiter = config.getDelimiter(); final CSVFormat format = CSVFormat.newFormat(delimiter).withTrailingDelimiter(false).withRecordSeparator('\n'); try (final ZipOutputStream zout = new ZipOutputStream(out, StandardCharsets.UTF_8)) { if (config.isWriteSingleFile()) {
/** * parseFile() method is used to parse the CSV file using the delimiter specified in CSV simulation Configuration * * @param delimiter delimiter to be used when parsing CSV file * @throws IOException if an error occurs when creating a CSVReader */ private CSVParser parseFile(String delimiter) throws IOException { switch (delimiter) { case ",": return new CSVParser(fileReader, CSVFormat.DEFAULT); case ";": return new CSVParser(fileReader, CSVFormat.EXCEL); case "\\t": return new CSVParser(fileReader, CSVFormat.TDF); default: return new CSVParser(fileReader, CSVFormat.newFormat(delimiter.charAt(0))); } }
static int write(final ReadOnlyTimeSeries timeSeries, final SerializationConfiguration config, final Writer writer) throws IOException { Objects.requireNonNull(timeSeries); Objects.requireNonNull(config); Objects.requireNonNull(writer); final FendodbSerializationFormat format = config.getFormat(); final int cnt; switch (format) { case JSON: cnt = write(timeSeries, config, writer, false); writer.flush(); break; case XML: cnt = write(timeSeries, config, writer, true); writer.flush(); break; default: final char delimiter = config.getDelimiter(); final CSVFormat csvFormat = CSVFormat.newFormat(delimiter).withTrailingDelimiter(false).withRecordSeparator('\n'); try (final CSVPrinter printer = new CSVPrinter(writer, csvFormat);) { cnt = write(timeSeries, config, printer); } } return cnt; }
/** * Write all time series to a single file * @param writer * @param timeSeries * @param config */ private final static void write(final Writer writer, final List<FendoTimeSeries> timeSeries, final DumpConfiguration config) { final char delimiter = config.getDelimiter(); // TODO implement JSON and XML serialization final CSVFormat format = CSVFormat.newFormat(delimiter).withTrailingDelimiter(false).withRecordSeparator('\n'); try (final CSVPrinter printer = new CSVPrinter(writer, format)) { SerializerImpl.write(timeSeries, config, printer); } catch (IOException e) { throw new UncheckedIOException(e); } }
/** * 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); }
protected void parseCSV(Reader in, String[] header, PerformanceReport report) throws IOException { CSVFormat csvFormat = CSVFormat.newFormat(delimiter).withHeader(header).withQuote('"').withSkipHeaderRecord(); Iterable<CSVRecord> records = csvFormat.parse(in); for (CSVRecord record : records) { final HttpSample sample = getSample(record); try { report.addSample(sample); } catch (SAXException e) { throw new IllegalStateException("Error parsing file '" + report.getReportFileName() + "': Unable to add sample for CSVRecord " + record, e); } } }
/** * * @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; } }
/** * 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); }
/** * Each String in the stream is a CSV file * @return stream of parsed insert queries */ public Stream<Map<String, Object>> convert() { try{ CSVParser csvParser = CSVFormat.newFormat(separator) .withIgnoreEmptyLines() .withEscape('\\' ) .withFirstRecordAsHeader() .withQuote(quote) .withNullString(nullString) .parse(reader); return stream(csvParser.iterator()).map(this::parse); } catch (IOException e){ throw 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; }