当前位置: 首页>>代码示例>>Java>>正文


Java CsvParserSettings.setHeaderExtractionEnabled方法代码示例

本文整理汇总了Java中com.univocity.parsers.csv.CsvParserSettings.setHeaderExtractionEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java CsvParserSettings.setHeaderExtractionEnabled方法的具体用法?Java CsvParserSettings.setHeaderExtractionEnabled怎么用?Java CsvParserSettings.setHeaderExtractionEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.univocity.parsers.csv.CsvParserSettings的用法示例。


在下文中一共展示了CsvParserSettings.setHeaderExtractionEnabled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
/**
 * Returns a DataFrame parsed from the stream specified stream
 * @param stream    the stream to parse
 * @return          the DataFrame parsed from stream
 * @throws IOException      if there stream read error
 */
private DataFrame<R,String> parse(CsvSourceOptions<R> options, InputStream stream) throws IOException {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, options.getCharset().orElse(StandardCharsets.UTF_8)))) {
        final CsvRequestHandler handler = new CsvRequestHandler(options);
        final CsvParserSettings settings = new CsvParserSettings();
        settings.getFormat().setDelimiter(options.getDelimiter());
        settings.setHeaderExtractionEnabled(options.isHeader());
        settings.setLineSeparatorDetectionEnabled(true);
        settings.setRowProcessor(handler);
        settings.setIgnoreTrailingWhitespaces(true);
        settings.setIgnoreLeadingWhitespaces(true);
        settings.setMaxColumns(10000);
        settings.setReadInputOnSeparateThread(false);
        final CsvParser parser = new CsvParser(settings);
        parser.parse(reader);
        return handler.getFrame();
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:24,代码来源:CsvSource.java

示例2: parseIssues

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
/**
 * Method to start parsing issues from the provided input stream.
 *
 * @param inputStream
 *            stream that contains uploaded BlackDuck scan result file data.
 * @param beanProcessor
 *            BeanProcessor implementation that is responsible for fetching vulnerabilities from the
 *            rows of the provided black duck result CSV file.
 * @throws ScanParsingException
 * @throws IOException
 *             If an I/O error occurs during CSV file processing.
 * @throws IllegalArgumentException
 *             if inputStream and / or beanProcessor are null.
 */
public void parseIssues(final InputStream inputStream, final BeanProcessor<BlackDuckIssue> beanProcessor) throws ScanParsingException, IOException {
    LOG.info("Parsing issues for Black Duck");
    if (inputStream == null) {
        throw new IllegalArgumentException("inputStream cannot be null");
    }
    if (beanProcessor == null) {
        throw new IllegalArgumentException("beanProcessor cannot be null");
    }
    final CsvParserSettings parserSettings = new CsvParserSettings();
    parserSettings.setRowProcessor(beanProcessor);
    parserSettings.setHeaderExtractionEnabled(true);
    try (final InputStreamCsvParser inputStreamCsvParser = new InputStreamCsvParser(parserSettings, inputStream)) {
        inputStreamCsvParser.parse();
    }
}
 
开发者ID:blackducksoftware,项目名称:hub-fortify-parser,代码行数:30,代码来源:BlackDuckCSVParser.java

示例3: initialize

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
/**
 * Below method will be used to initialize the the parser
 *
 * @throws IOException
 */
public void initialize() throws IOException {
  CsvParserSettings parserSettings = new CsvParserSettings();
  parserSettings.getFormat().setDelimiter(csvParserVo.getDelimiter().charAt(0));
  parserSettings.getFormat().setComment(csvParserVo.getCommentCharacter().charAt(0));
  parserSettings.setLineSeparatorDetectionEnabled(true);
  parserSettings.setMaxColumns(
      getMaxColumnsForParsing(csvParserVo.getNumberOfColumns(), csvParserVo.getMaxColumns()));
  parserSettings.setNullValue("");
  parserSettings.setIgnoreLeadingWhitespaces(false);
  parserSettings.setIgnoreTrailingWhitespaces(false);
  parserSettings.setSkipEmptyLines(false);
  parserSettings.getFormat().setQuote(null == csvParserVo.getQuoteCharacter() ?
      '\"':csvParserVo.getQuoteCharacter().charAt(0));
  parserSettings.getFormat().setQuoteEscape(null == csvParserVo.getEscapeCharacter() ?
      '\\' :
      csvParserVo.getEscapeCharacter().charAt(0));
  blockCounter++;
  initializeReader();
  if (csvParserVo.getBlockDetailsList().get(blockCounter).getBlockOffset() == 0) {
    parserSettings.setHeaderExtractionEnabled(csvParserVo.isHeaderPresent());
  }
  parser = new CsvParser(parserSettings);
  parser.beginParsing(inputStreamReader);
}
 
开发者ID:carbondata,项目名称:carbondata,代码行数:30,代码来源:UnivocityCsvParser.java

示例4: example002RecordMetadata

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
@Test
public void example002RecordMetadata() throws Exception {

	CsvParserSettings settings = new CsvParserSettings();
	//the file used in the example uses '\n' as the line separator sequence.
	//the line separator sequence is defined here to ensure systems such as MacOS and Windows
	//are able to process this file correctly (MacOS uses '\r'; and Windows uses '\r\n').
	settings.getFormat().setLineSeparator("\n");

	settings.setHeaderExtractionEnabled(true);

	CsvParser parser = new CsvParser(settings);

	// parses all records in one go
	List<Record> allRecords = parser.parseAllRecords(getReader("/examples/example.csv"));

	//##CODE_START
	parser.getRecordMetadata().setTypeOfColumns(Long.class, "year", "price");
	parser.getRecordMetadata().setDefaultValueOfColumns("0", "Year");
	parser.getRecordMetadata().convertFields(Conversions.replace("\\.00", "")).set("Price");

	for (Record record : allRecords) {
		Long year = record.getLong("year");
		String model = record.getString("MODEL");
		Long price = record.getLong("Price");
		println(year + " " + model + ": $" + price);
	}

	//##CODE_END
	printAndValidate();
}
 
开发者ID:uniVocity,项目名称:univocity-parsers,代码行数:32,代码来源:RecordExamples.java

示例5: testInternal

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
@Test(dataProvider = "inputProvider")
public void testInternal(String input) {
    CsvParserSettings settings = new CsvParserSettings();
    settings.getFormat().setLineSeparator("\n");
    settings.setHeaderExtractionEnabled(true);

    CsvParser csvParser = new CsvParser(settings);

    csvParser.beginParsing(new StringReader(input));
    Record record = csvParser.parseNextRecord();
    RecordMetaData metaData = record.getMetaData();

    assertNotNull(metaData.headers());
    assertTrue(metaData.containsColumn("col1"));
    assertTrue(metaData.containsColumn("col2"));
}
 
开发者ID:uniVocity,项目名称:univocity-parsers,代码行数:17,代码来源:Github_109.java

示例6: testUnivocityCsvMapper

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
@Benchmark
public void testUnivocityCsvMapper(final Blackhole blackhole) throws Exception {
	BeanProcessor<SmallBenchmarkObject> rowProcessor = new BeanProcessor<SmallBenchmarkObject>(SmallBenchmarkObject.class) {

		@Override
		public void beanProcessed(SmallBenchmarkObject bean,
				ParsingContext context) {
			blackhole.consume(bean);
		}
		
	};

    CsvParserSettings parserSettings = new CsvParserSettings();
    parserSettings.setRowProcessor(rowProcessor);
    parserSettings.setHeaderExtractionEnabled(true);

    com.univocity.parsers.csv.CsvParser parser = new com.univocity.parsers.csv.CsvParser(parserSettings);

    parser.parse(reader);
}
 
开发者ID:arnaudroger,项目名称:orm-benchmark,代码行数:21,代码来源:CsvMapperBenchmark.java

示例7: parseCSV

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
public void parseCSV(String fileName){
    CsvParserSettings parserSettings = new CsvParserSettings();
    parserSettings.setLineSeparatorDetectionEnabled(true);
    RowListProcessor rowProcessor = new RowListProcessor();
   parserSettings.setRowProcessor(rowProcessor);
    parserSettings.setHeaderExtractionEnabled(true);
    CsvParser parser = new CsvParser(parserSettings);
    parser.parse(new File(fileName));

    String[] headers = rowProcessor.getHeaders();
    List<String[]> rows = rowProcessor.getRows();
    for (int i = 0; i < rows.size(); i++){
    	System.out.println(Arrays.asList(rows.get(i)));
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:16,代码来源:TestUnivocity.java

示例8: getItererableCsv

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
private Iterable<Record> getItererableCsv(String source, String iteratorExpression) {
	CsvParserSettings settings = new CsvParserSettings();
	settings.setHeaderExtractionEnabled(true);
	settings.setLineSeparatorDetectionEnabled(true);
	settings.setDelimiterDetectionEnabled(true);
	settings.setReadInputOnSeparateThread(true);
	CsvParser parser = new CsvParser(settings);
	
	return parser.iterateRecords(new StringReader(source));
}
 
开发者ID:carml,项目名称:carml,代码行数:11,代码来源:CsvResolver.java

示例9: csvParser

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
static RowListProcessor csvParser(String path, boolean extractHeader) {
    CsvParserSettings parserSettings = new CsvParserSettings();
    parserSettings.setLineSeparatorDetectionEnabled(true);
    RowListProcessor rowProcessor = new RowListProcessor();
    parserSettings.setRowProcessor(rowProcessor);
    parserSettings.setHeaderExtractionEnabled(extractHeader);
    new CsvParser(parserSettings).parse(new File(path));
    return rowProcessor;
}
 
开发者ID:gboleslavsky,项目名称:HiveUnit,代码行数:10,代码来源:H.java

示例10: parseCSV

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
public List<IsoformOverride> parseCSV()
{
    BeanListProcessor<IsoformOverride> rowProcessor = new BeanListProcessor<>(IsoformOverride.class);

    CsvParserSettings parserSettings = new CsvParserSettings();
    parserSettings.setHeaderExtractionEnabled(true);
    parserSettings.getFormat().setDelimiter('\t');
    parserSettings.setRowProcessor(rowProcessor);

    CsvParser parser = new CsvParser(parserSettings);
    parser.parse(getReader(this.resourceURI));

    return rowProcessor.getBeans();
}
 
开发者ID:genome-nexus,项目名称:genome-nexus,代码行数:15,代码来源:IsoformOverrideRepositoryImpl.java

示例11: getParser

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
private CsvParser getParser() {
    CsvParserSettings parserSettings = new CsvParserSettings();
    parserSettings.setLineSeparatorDetectionEnabled(true);
    parserSettings.setHeaderExtractionEnabled(true);
    parserSettings.selectFields("label", "elapsed", "success", "timeStamp");
    RowListProcessor rowProcessor = new RowListProcessor();
    parserSettings.setProcessor(new ConcurrentRowProcessor(rowProcessor));
    return new CsvParser(parserSettings);
}
 
开发者ID:deliverymind,项目名称:lightning,代码行数:10,代码来源:JMeterCSVFileReader.java

示例12: getParser

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
private CsvParser getParser() {
    CsvParserSettings parserSettings = new CsvParserSettings();
    parserSettings.setLineSeparatorDetectionEnabled(true);
    parserSettings.setHeaderExtractionEnabled(false);
    parserSettings.selectIndexes(TIMESTAMP, VALUE, HOST_AND_METRIC);
    RowListProcessor rowProcessor = new RowListProcessor();
    parserSettings.setProcessor(new ConcurrentRowProcessor(rowProcessor));
    return new CsvParser(parserSettings);
}
 
开发者ID:deliverymind,项目名称:lightning,代码行数:10,代码来源:PerfMonDataReader.java

示例13: example001ParseRecords

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
@Test
public void example001ParseRecords() throws Exception {

	CsvParserSettings settings = new CsvParserSettings();
	//the file used in the example uses '\n' as the line separator sequence.
	//the line separator sequence is defined here to ensure systems such as MacOS and Windows
	//are able to process this file correctly (MacOS uses '\r'; and Windows uses '\r\n').
	settings.getFormat().setLineSeparator("\n");

	//##CODE_START

	settings.getFormat().setDelimiter(';');
	settings.getFormat().setQuoteEscape('\\');

	settings.setHeaderExtractionEnabled(true);

	CsvParser parser = new CsvParser(settings);

	// parses all records in one go
	List<Record> allRecords = parser.parseAllRecords(getReader("/examples/european.csv"));

	double sumOfPrices = 0.0;
	for (Record record : allRecords) {
		//Let's use the convenience methods in the record class to convert the parsed data into a Double.
		//Numbers are stored in the file using the european format.
		//Here we read the "price" column, using the "0,00" format mask, and decimal separator set to comma.
		Double price = record.getDouble("price", "0,00", "decimalSeparator=,");

		if (price != null) {
			sumOfPrices += price;
		}
	}

	print("Average car price: $" + (sumOfPrices / allRecords.size()));
	//##CODE_END
	printAndValidate();
}
 
开发者ID:uniVocity,项目名称:univocity-parsers,代码行数:38,代码来源:RecordExamples.java

示例14: readRecordsFromTestFile

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
/**
 * Return a List<String[]> of the parsed file.
 * The first item in the list <code>list.get(0)</code> is a <code>String[]<code/> of headers. The rest
 * of the elements are rows in the file
 *
 * @param pathToFile Full path in File System to a CSV file that contains records
 * @return List<String[]> where the first record is the field names and the rest are the records
 */
public static List<String[]> readRecordsFromTestFile(String pathToFile) {
    // The settings object provides many configuration options
    CsvParserSettings parserSettings = new CsvParserSettings();

    //You can configure the parser to automatically detect what line separator sequence is in the input
    parserSettings.setLineSeparatorDetectionEnabled(true);

    // A RowListProcessor stores each parsed row in a List.
    RowListProcessor rowProcessor = new RowListProcessor();

    // You can configure the parser to use a RowProcessor to process the values of each parsed row.
    // You will find more RowProcessors in the 'com.univocity.parsers.common.processor' package, but you can also create your own.
    parserSettings.setRowProcessor(rowProcessor);

    parserSettings.setEmptyValue(StringUtils.EMPTY);
    parserSettings.setNullValue(StringUtils.EMPTY);

    // Let's consider the first parsed row as the headers of each column in the file.
    parserSettings.setHeaderExtractionEnabled(true);

    DatasetParser datasetParser = new DatasetParser();
    datasetParser.getParserForFile(pathToFile, parserSettings);

    // get the parsed records from the RowListProcessor here.
    // Note that different implementations of RowProcessor will provide different sets of functionalities.
    String[] headers = rowProcessor.getHeaders();
    List<String[]> rows = rowProcessor.getRows();
    List<String[]> results = new ArrayList<>();
    results.add(headers);
    results.addAll(rows);
    return results;
}
 
开发者ID:sapirgolan,项目名称:MFIBlocking,代码行数:41,代码来源:UtilitiesForBlocksAndRecords.java

示例15: example003RecordToMap

import com.univocity.parsers.csv.CsvParserSettings; //导入方法依赖的package包/类
@Test
public void example003RecordToMap() throws Exception {
	CsvParserSettings settings = new CsvParserSettings();
	//the file used in the example uses '\n' as the line separator sequence.
	//the line separator sequence is defined here to ensure systems such as MacOS and Windows
	//are able to process this file correctly (MacOS uses '\r'; and Windows uses '\r\n').
	settings.getFormat().setLineSeparator("\n");

	settings.setHeaderExtractionEnabled(true);

	CsvParser parser = new CsvParser(settings);

	//##CODE_START
	// this time, lest's parse on demand.
	parser.beginParsing(getReader("/examples/example.csv"));

	//null year should become 0000
	parser.getRecordMetadata().setDefaultValueOfColumns("0000", "Year");

	//decimal separator in prices will be replaced by comma
	parser.getRecordMetadata().convertFields(Conversions.replace("\\.00", ",00")).set("Price");

	//make will be uppercase
	parser.getRecordMetadata().convertFields(Conversions.toUpperCase()).set("make");

	//let's fill a map with values.
	LinkedHashMap<String, Object> values = new LinkedHashMap<String, Object>();

	//create instances of Record on demand
	Record record;
	while ((record = parser.parseNextRecord()) != null) {
		//we can get the original values of selected columns (by name or index) in a map.
		//Map<String, String> originalValues = record.toFieldMap();

		//to get the converted values as specified in the record metadata use the method ending with "ObjectMap"
		//Map<String, Object> convertedValues = record.toFieldObjectMap();

		//all map methods allow you to choose which columns to get data from. Here we select just the (originally parsed) year:
		Map<String, String> originalYearValues = record.toFieldMap("YEAR"); //the character case of the selection is kept regardless of what the headers contain.
		println(originalYearValues); //original values, no conversions applied.

		//instead of creating new maps every time, we can also reuse maps and invoke the "fill" methods
		record.fillFieldObjectMap(values);
		println(values);

	}

	//##CODE_END
	printAndValidate();
}
 
开发者ID:uniVocity,项目名称:univocity-parsers,代码行数:51,代码来源:RecordExamples.java


注:本文中的com.univocity.parsers.csv.CsvParserSettings.setHeaderExtractionEnabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。