au.com.bytecode.opencsv.CSVParser Java Examples
The following examples show how to use
au.com.bytecode.opencsv.CSVParser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CsvStreamReader.java From Quicksql with MIT License | 6 votes |
/** * Creates a CsvStreamReader with supplied separator and quote char. * * @param source The file to an underlying CSV source * @param separator The delimiter to use for separating entries * @param quoteChar The character to use for quoted elements * @param escape The character to use for escaping a separator or quote * @param line The line number to skip for start reading * @param strictQuotes Sets if characters outside the quotes are ignored * @param ignoreLeadingWhiteSpace If true, parser should ignore * white space before a quote in a field */ private CsvStreamReader(Source source, char separator, char quoteChar, char escape, int line, boolean strictQuotes, boolean ignoreLeadingWhiteSpace) { super(new StringReader("")); // dummy call to base constructor contentQueue = new ArrayDeque<>(); TailerListener listener = new CsvContentListener(contentQueue); tailer = Tailer.create(source.file(), listener, DEFAULT_MONITOR_DELAY, false, true, 4096); this.parser = new CSVParser(separator, quoteChar, escape, strictQuotes, ignoreLeadingWhiteSpace); this.skipLines = line; try { // wait for tailer to capture data Thread.sleep(DEFAULT_MONITOR_DELAY); } catch (InterruptedException e) { throw new RuntimeException(e); } }
Example #2
Source File: CsvStreamReader.java From calcite with Apache License 2.0 | 6 votes |
/** * Creates a CsvStreamReader with supplied separator and quote char. * * @param source The file to an underlying CSV source * @param separator The delimiter to use for separating entries * @param quoteChar The character to use for quoted elements * @param escape The character to use for escaping a separator or quote * @param line The line number to skip for start reading * @param strictQuotes Sets if characters outside the quotes are ignored * @param ignoreLeadingWhiteSpace If true, parser should ignore * white space before a quote in a field */ private CsvStreamReader(Source source, char separator, char quoteChar, char escape, int line, boolean strictQuotes, boolean ignoreLeadingWhiteSpace) { super(new StringReader("")); // dummy call to base constructor contentQueue = new ArrayDeque<>(); TailerListener listener = new CsvContentListener(contentQueue); tailer = Tailer.create(source.file(), listener, DEFAULT_MONITOR_DELAY, false, true, 4096); this.parser = new CSVParser(separator, quoteChar, escape, strictQuotes, ignoreLeadingWhiteSpace); this.skipLines = line; try { // wait for tailer to capture data Thread.sleep(DEFAULT_MONITOR_DELAY); } catch (InterruptedException e) { throw new RuntimeException(e); } }
Example #3
Source File: TWBTranslationServiceImpl.java From AIDR with GNU Affero General Public License v3.0 | 6 votes |
@Transactional private void processResponseDocumentContent(String content, Integer orderId, Integer projectId) throws Exception { BufferedReader reader = new BufferedReader(new StringReader(content)); String line; String[] toks; CSVParser parser = new CSVParser(); int counter = 1; reader.readLine(); //skip the first line which is a header. while ((line = reader.readLine()) != null) { counter++; line = line.trim(); if (line.length() <= 0) continue; try { toks = parser.parseLine(line); if (toks.length != 4) { throw new RuntimeException("Invalid number of columns in row " + counter); } updateTranslation(orderId, new Long(toks[0]), toks[1], toks[2], toks[3]); } catch (Exception e) { logger.error("Invalid line: " + line + " (" + e.getMessage() + ")"); throw new RuntimeException("Invalid line: " + line + " (" + e.getMessage() + ")"); } } }
Example #4
Source File: CsvStreamReader.java From Quicksql with MIT License | 5 votes |
CsvStreamReader(Source source) { this(source, CSVParser.DEFAULT_SEPARATOR, CSVParser.DEFAULT_QUOTE_CHARACTER, CSVParser.DEFAULT_ESCAPE_CHARACTER, DEFAULT_SKIP_LINES, CSVParser.DEFAULT_STRICT_QUOTES, CSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE); }
Example #5
Source File: CsvLogRecordParser.java From cognition with Apache License 2.0 | 5 votes |
public void parse(Reader fileReader, String fileType, LogRecordCollector collector) throws IOException { try (CSVReader csvReader = new CSVReader( fileReader, config.getDelimiter(), CSVParser.DEFAULT_QUOTE_CHARACTER, CSVParser.NULL_CHARACTER);) { long line = 0; String[] headers = csvReader.readNext(); line++; String[] fieldNames = constructFieldNames(headers, fileType, config.isCleanKeysForES()); String[] record = null; while ((record = csvReader.readNext()) != null) { if (record.length != headers.length) { // unmatched record length LOGGER.warn("Unmatched record column count detected at line {} - header: {} record: {}", line, headers.length, record.length); continue; } LogRecord logRecord = new LogRecord(); for (int i = 0; i < fieldNames.length; i++) { if (config.isSkipBlankFields() && StringUtils.isBlank(record[i])) { // skip } else { String value = config.isTrimFieldValue() ? StringUtils.trim(record[i]) : record[i]; logRecord.setValue(fieldNames[i], value); } } collector.emit(logRecord); } } }
Example #6
Source File: CsvStreamReader.java From calcite with Apache License 2.0 | 5 votes |
CsvStreamReader(Source source) { this(source, CSVParser.DEFAULT_SEPARATOR, CSVParser.DEFAULT_QUOTE_CHARACTER, CSVParser.DEFAULT_ESCAPE_CHARACTER, DEFAULT_SKIP_LINES, CSVParser.DEFAULT_STRICT_QUOTES, CSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE); }
Example #7
Source File: AvroCSV.java From parquet-mr with Apache License 2.0 | 5 votes |
static CSVParser newParser(CSVProperties props) { return new CSVParser( props.delimiter.charAt(0), props.quote.charAt(0), props.escape.charAt(0), false /* strict quotes off: don't ignore unquoted strings */, true /* ignore leading white-space */ ); }
Example #8
Source File: FileFixTableCreator.java From celos with Apache License 2.0 | 5 votes |
@Override public FixTable create(TestRun testRun) throws Exception { try (CSVReader reader = new CSVReader(getFileReader(testRun), separator, CSVParser.DEFAULT_QUOTE_CHARACTER, CSVParser.DEFAULT_ESCAPE_CHARACTER)) { List<String[]> myEntries = reader.readAll(); String[] colNames = myEntries.get(0); List<String[]> rowData = myEntries.subList(1, myEntries.size()); return StringArrayFixTableCreator.createFixTable(colNames, rowData); } }
Example #9
Source File: CSVUtil.java From kite with Apache License 2.0 | 5 votes |
public static CSVParser newParser(CSVProperties props) { return new CSVParser( props.delimiter.charAt(0), props.quote.charAt(0), props.escape.charAt(0), false /* strict quotes off: don't ignore unquoted strings */, true /* ignore leading white-space */ ); }
Example #10
Source File: TestFileIterator.java From metanome-algorithms with Apache License 2.0 | 4 votes |
public TestFileIterator(String relationName, Reader reader, char separator, char quotechar, int skipLines, boolean hasHeader) throws InputIterationException { this(relationName, reader, separator, quotechar, CSVParser.DEFAULT_ESCAPE_CHARACTER, skipLines, CSVParser.DEFAULT_STRICT_QUOTES, CSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE, hasHeader); }
Example #11
Source File: InferredSchema.java From DataVec with Apache License 2.0 | 4 votes |
public InferredSchema(String pathToCsv, DataType defaultType, char delimiter) { this.pathToCsv = pathToCsv; this.defaultType = defaultType; this.csvParser = new CSVParser(delimiter); }
Example #12
Source File: InferredSchema.java From DataVec with Apache License 2.0 | 4 votes |
public InferredSchema(String pathToCsv, DataType defaultType, char delimiter, char quote) { this.pathToCsv = pathToCsv; this.defaultType = defaultType; this.csvParser = new CSVParser(delimiter, quote); }
Example #13
Source File: InferredSchema.java From DataVec with Apache License 2.0 | 4 votes |
public InferredSchema(String pathToCsv, DataType defaultType, char delimiter, char quote, char escape) { this.pathToCsv = pathToCsv; this.defaultType = defaultType; this.csvParser = new CSVParser(delimiter, quote, escape); }
Example #14
Source File: InferredSchema.java From deeplearning4j with Apache License 2.0 | 4 votes |
public InferredSchema(String pathToCsv, DataType defaultType, char delimiter) { this.pathToCsv = pathToCsv; this.defaultType = defaultType; this.csvParser = new CSVParser(delimiter); }
Example #15
Source File: InferredSchema.java From deeplearning4j with Apache License 2.0 | 4 votes |
public InferredSchema(String pathToCsv, DataType defaultType, char delimiter, char quote) { this.pathToCsv = pathToCsv; this.defaultType = defaultType; this.csvParser = new CSVParser(delimiter, quote); }
Example #16
Source File: InferredSchema.java From deeplearning4j with Apache License 2.0 | 4 votes |
public InferredSchema(String pathToCsv, DataType defaultType, char delimiter, char quote, char escape) { this.pathToCsv = pathToCsv; this.defaultType = defaultType; this.csvParser = new CSVParser(delimiter, quote, escape); }