public CSVRecordReader(final InputStream in, final ComponentLog logger, final RecordSchema schema, final CSVFormat csvFormat, final boolean hasHeader, final boolean ignoreHeader, final String dateFormat, final String timeFormat, final String timestampFormat, final String encoding) throws IOException { super(logger, schema, hasHeader, ignoreHeader, dateFormat, timeFormat, timestampFormat); final Reader reader = new InputStreamReader(new BOMInputStream(in), encoding); CSVFormat withHeader; if (hasHeader) { withHeader = csvFormat.withSkipHeaderRecord(); if (ignoreHeader) { withHeader = withHeader.withHeader(schema.getFieldNames().toArray(new String[0])); } else { withHeader = withHeader.withFirstRecordAsHeader(); } } else { withHeader = csvFormat.withHeader(schema.getFieldNames().toArray(new String[0])); } csvParser = new CSVParser(reader, withHeader); }
@Override public RecordSchema getSchema(Map<String, String> variables, final InputStream contentStream, final RecordSchema readSchema) throws SchemaNotFoundException { if (this.context == null) { throw new SchemaNotFoundException("Schema Access Strategy intended only for validation purposes and cannot obtain schema"); } try { final CSVFormat csvFormat = CSVUtils.createCSVFormat(context).withFirstRecordAsHeader(); try (final Reader reader = new InputStreamReader(new BOMInputStream(contentStream)); final CSVParser csvParser = new CSVParser(reader, csvFormat)) { final List<RecordField> fields = new ArrayList<>(); for (final String columnName : csvParser.getHeaderMap().keySet()) { fields.add(new RecordField(columnName, RecordFieldType.STRING.getDataType(), true)); } return new SimpleRecordSchema(fields); } } catch (final Exception e) { throw new SchemaNotFoundException("Failed to read Header line from CSV", e); } }
.withRecordSeparator(recordSeparator); try (final CSVParser parser = new CSVParser(reader, format)) { ThreadMethods.throttledExecution(StreamMethods.enumerate(StreamMethods.stream(parser.spliterator(), false)).skip(skip).limit(limit), e -> { Integer rId = e.getKey();
(double) totalHunspellComputationTime.get() / numMatches.get()))); SuggestionsOrdererConfig.setNgramsPath(args[1]); try (CSVParser parser = new CSVParser(new FileReader(args[0]), CSVFormat.DEFAULT.withFirstRecordAsHeader())) { for (CSVRecord record : parser) { String lang = record.get("language");
try (CSVParser parser = new CSVParser(new FileReader(correctionsFileLocation), CSVFormat.DEFAULT.withFirstRecordAsHeader())) { for (CSVRecord record : parser) {
/** * Parses the specified content. * * <p> * See also the various static parse methods on {@link CSVParser}. * </p> * * @param in * the input stream * @return a parser over a stream of {@link CSVRecord}s. * @throws IOException * If an I/O error occurs */ public CSVParser parse(final Reader in) throws IOException { return new CSVParser(in, this); }
/** * Creates a CSV parser using the given {@link CSVFormat} * * <p> * If you do not read all records from the given {@code reader}, you should call {@link #close()} on the parser, * unless you close the {@code reader}. * </p> * * @param reader * a Reader containing CSV-formatted input. Must not be null. * @param format * the CSVFormat used for CSV parsing. Must not be null. * @return a new CSVParser configured with the given reader and format. * @throws IllegalArgumentException * If the parameters of the format are inconsistent or if either reader or format are null. * @throws IOException * If there is a problem reading the header or skipping the first record * @since 1.5 */ public static CSVParser parse(final Reader reader, final CSVFormat format) throws IOException { return new CSVParser(reader, format); }
public CSVRecord parse(String input) throws IOException { CSVParser csvParser = new CSVParser(new StringReader(input), this.csvFormat); return Iterables.getFirst(csvParser, null); } }
@Override public CSVRecord parse(String input) throws IOException { // TODO Creating a new parser for each line seems terribly inefficient but // there's no public way to parse single lines via commons-csv. We should update // it to create a LineParser class like this one. CSVParser csvParser = new CSVParser(new StringReader(input), csvFormat); return Iterables.getFirst(csvParser, null); } }
public void upsert(Reader reader) throws Exception { CSVParser parser = new CSVParser(reader,format); upsert(parser); }
/** * Creates a parser for the given {@link File}. * * @param file * a CSV file. Must not be null. * @param charset * A Charset * @param format * the CSVFormat used for CSV parsing. Must not be null. * @return a new parser * @throws IllegalArgumentException * If the parameters of the format are inconsistent or if either file or format are null. * @throws IOException * If an I/O error occurs */ @SuppressWarnings("resource") public static CSVParser parse(final File file, final Charset charset, final CSVFormat format) throws IOException { Assertions.notNull(file, "file"); Assertions.notNull(format, "format"); return new CSVParser(new InputStreamReader(new FileInputStream(file), charset), format); }
/** * Creates a parser for the given {@link String}. * * @param string * a CSV string. Must not be null. * @param format * the CSVFormat used for CSV parsing. Must not be null. * @return a new parser * @throws IllegalArgumentException * If the parameters of the format are inconsistent or if either string or format are null. * @throws IOException * If an I/O error occurs */ public static CSVParser parse(final String string, final CSVFormat format) throws IOException { Assertions.notNull(string, "string"); Assertions.notNull(format, "format"); return new CSVParser(new StringReader(string), format); }
/** * Creates a parser for the given URL. * * <p> * If you do not read all records from the given {@code url}, you should call {@link #close()} on the parser, unless * you close the {@code url}. * </p> * * @param url * a URL. Must not be null. * @param charset * the charset for the resource. Must not be null. * @param format * the CSVFormat used for CSV parsing. Must not be null. * @return a new parser * @throws IllegalArgumentException * If the parameters of the format are inconsistent or if either url, charset or format are null. * @throws IOException * If an I/O error occurs */ public static CSVParser parse(final URL url, final Charset charset, final CSVFormat format) throws IOException { Assertions.notNull(url, "url"); Assertions.notNull(charset, "charset"); Assertions.notNull(format, "format"); return new CSVParser(new InputStreamReader(url.openStream(), charset), format); }
try (CSVParser csvParser = new CSVParser(reader, CSVFormat.TDF)) { Iterator<CSVRecord> iterator = csvParser.iterator();
final CSVParser parser = new CSVParser(in, CSVFormat.DEFAULT.withHeader());
+ stockTableName); ResultSet phoenixResultSet = statement.executeQuery(); parser = new CSVParser(new StringReader( STOCK_CSV_VALUES_WITH_HEADER), csvUtil.getFormat()); for (CSVRecord record : parser) {
+ stockTableName); ResultSet phoenixResultSet = statement.executeQuery(); parser = new CSVParser(new StringReader( STOCK_CSV_VALUES), csvUtil.getFormat()); for (CSVRecord record : parser) {
+ stockTableName); ResultSet phoenixResultSet = statement.executeQuery(); parser = new CSVParser(new StringReader(STOCK_CSV_VALUES), csvUtil.getFormat()); for (CSVRecord record : parser) {
CSVParser csvParser = new CSVParser(reader, CSVFormat.TDF)) { xhtml.startElement("table");
CSVParser csvParser = new CSVParser(reader, CSVFormat.TDF)) { Iterator<CSVRecord> iterator = csvParser.iterator();