try (final InputStream is = new FileInputStream(csvFile)) { try (final InputStreamReader reader = new InputStreamReader(is, charset)) { final Iterable<CSVRecord> records = csvFormat.withFirstRecordAsHeader().parse(reader); for (final CSVRecord record : records) { final String key = record.get(lookupKeyColumn);
try (final InputStream is = new FileInputStream(csvFile)) { try (final InputStreamReader reader = new InputStreamReader(is, charset)) { final CSVParser records = csvFormat.withFirstRecordAsHeader().parse(reader); RecordSchema lookupRecordSchema = null; for (final CSVRecord record : records) {
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); } }
(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) {
@OnEnabled public void storeCsvFormat(final ConfigurationContext context) { this.csvParser = context.getProperty(CSV_PARSER).getValue(); this.csvFormat = CSVUtils.createCSVFormat(context); this.dateFormat = context.getProperty(DateTimeUtils.DATE_FORMAT).getValue(); this.timeFormat = context.getProperty(DateTimeUtils.TIME_FORMAT).getValue(); this.timestampFormat = context.getProperty(DateTimeUtils.TIMESTAMP_FORMAT).getValue(); this.firstLineIsHeader = context.getProperty(CSVUtils.FIRST_LINE_IS_HEADER).asBoolean(); this.ignoreHeader = context.getProperty(CSVUtils.IGNORE_CSV_HEADER).asBoolean(); this.charSet = context.getProperty(CSVUtils.CHARSET).getValue(); // Ensure that if we are deriving schema from header that we always treat the first line as a header, // regardless of the 'First Line is Header' property final String accessStrategy = context.getProperty(SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY).getValue(); if (headerDerivedAllowableValue.getValue().equals(accessStrategy)) { this.csvFormat = this.csvFormat.withFirstRecordAsHeader(); this.firstLineIsHeader = true; } }
public GrblLookups(String prefix) { String filename = prefix + "_" + Localization.loadedLocale() + ".csv"; URL u = GrblLookups.class.getResource(pathFor(filename)); if (u == null) { filename = prefix + "_en_US.csv"; } try { try (BufferedReader reader = new BufferedReader( new InputStreamReader( GrblLookups.class.getResourceAsStream(pathFor(filename))))) { Iterable<CSVRecord> records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(reader); for (CSVRecord record : records) { List<String> list = Lists.newArrayList(record.iterator()); lookups.put(record.get(0), list.toArray(new String[0])); } } } catch (IOException ex) { System.out.println("Unable to load GRBL resources."); ex.printStackTrace(); } }
format = format.withFirstRecordAsHeader();
CSVFormat format = CSVFormat.newFormat(theDelimiter).withFirstRecordAsHeader(); if (theQuoteMode != null) { format = format.withQuote('"').withQuoteMode(theQuoteMode);
/** * Sets up the CSV parser with tab-delimited format, and first row as header. * * @return a {@link CSVRecord parser} */ @Nonnull private CSVFormat setupCSVParser() { return CSVFormat.TDF.withFirstRecordAsHeader(); }
.withRecordSeparator("\n") .withHeader(Header.class) .withFirstRecordAsHeader() .withIgnoreHeaderCase() .withIgnoreEmptyLines()
public TransactionLevelFeeReport(String urlValue) throws IOException, ParseException { if (urlValue == null || "".equals(urlValue)) { this.valid = false; return; } this.valid = true; URL url = new URL(urlValue); InputStreamReader is = new InputStreamReader(url.openStream()); for (CSVRecord record : CSVFormat.EXCEL.withFirstRecordAsHeader().parse(is)) { rows.add(new TransactionLevelFeeReportRow(record)); } }
public TransactionLevelFeeReport(String urlValue) throws IOException, ParseException { if (urlValue == null || "".equals(urlValue)) { this.valid = false; return; } this.valid = true; URL url = new URL(urlValue); InputStreamReader is = new InputStreamReader(url.openStream()); for (CSVRecord record : CSVFormat.EXCEL.withFirstRecordAsHeader().parse(is)) { rows.add(new TransactionLevelFeeReportRow(record)); } }
public TransactionLevelFeeReport(String urlValue) throws IOException, ParseException { if (urlValue == null || "".equals(urlValue)) { this.valid = false; return; } this.valid = true; URL url = new URL(urlValue); InputStreamReader is = new InputStreamReader(url.openStream()); for (CSVRecord record : CSVFormat.EXCEL.withFirstRecordAsHeader().parse(is)) { rows.add(new TransactionLevelFeeReportRow(record)); } }
public List<KeyPairs> fromCSV(InputStream inputStream) throws Exception { Reader reader = new InputStreamReader(inputStream); Iterable<CSVRecord> records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(reader); Iterable<CSVRecord> iterable = () -> records.iterator(); Stream<CSVRecord> stream = StreamSupport.stream(iterable.spliterator(), false); return stream.map((entry) -> { String ethAddress = entry.get(0); String btcAddress = entry.get(1); LOG.info("Reading: ETH={} BTC={}", ethAddress, btcAddress); return new KeyPairs(btcAddress, ethAddress, true); }).collect(Collectors.toList()); }
public IpfixInformationElements() throws IOException { Reader in = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(CSVSOURCE)); Iterable<CSVRecord> records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(in); Map<Integer, Element> buildElements = new HashMap<>(); Matcher mtch = RANGEPATTERN.matcher(""); for (CSVRecord record : records) { if (mtch.reset(record.get(0)).matches()) { continue; } Element e = new Element(record.toMap()); buildElements.put(e.elementId, e); } elements = Collections.unmodifiableMap(buildElements); }
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 static CSVParser readCsvRecords(List<String> header, String content) { try { CSVFormat csvFormat = CSVFormat.RFC4180; if (header.isEmpty()) { csvFormat = csvFormat.withFirstRecordAsHeader(); } return csvFormat. withIgnoreSurroundingSpaces(). withIgnoreEmptyLines(). withTrim(). withDelimiter(','). parse(new StringReader(content)); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void setFromArgs(Namespace args) throws CommandLineParsingException { super.setFromArgs(args); csv = args.getString("input"); format = ((CSVFormat.Predefined) args.get("type")).getFormat(); chr = args.getInt("chr") - 1; pos = args.getInt("pos") - 1; ref = args.getInt("ref") - 1; alt = args.getInt("alt") - 1; header = args.getBoolean("header"); if ( header) format = format.withFirstRecordAsHeader().withSkipHeaderRecord(); }