com.opencsv.CSVReader.getLinesRead()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(299)

本文整理了Java中com.opencsv.CSVReader.getLinesRead()方法的一些代码示例,展示了CSVReader.getLinesRead()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CSVReader.getLinesRead()方法的具体详情如下:
包路径:com.opencsv.CSVReader
类名称:CSVReader
方法名:getLinesRead

CSVReader.getLinesRead介绍

[英]This method returns the number of lines that has been read from the reader passed into the CSVReader.

Given the following data:

First line in the file 
some other descriptive line 
a,b,c 
a,"b\nb",c

With a CSVReader constructed like so:
CSVReader c = builder.withCSVParser(new CSVParser()) .withSkipLines(2) .build();
The initial call to getLinesRead() will be 0. After the first call to readNext() then getLinesRead() will return 3 (because the header was read). After the second call to read the blank line then getLinesRead() will return 4 (still a read). After the third call to readNext(), getLinesRead() will return 6 because it took two line reads to retrieve this record. Subsequent calls to readNext() (since we are out of data) will not increment the number of lines read.
[中]此方法返回从传递到CSVReader的读取器读取的行数。
鉴于以下数据:

First line in the file 
some other descriptive line 
a,b,c 
a,"b\nb",c

使用如下构造的CSVReader:
CSVReader c = builder.withCSVParser(new CSVParser()) .withSkipLines(2) .build();
对getLinesRead()的初始调用将为0。在第一次调用readNext()之后,getLinesRead()将返回3(因为标头已被读取)。在读取空白行的第二次调用之后,GETLIN Sead()将返回4(仍然是读取)。在第三次调用readNext()之后,getLinesRead()将返回6,因为检索此记录需要两行读取。对readNext()的后续调用(因为数据不足)不会增加读取的行数。

代码示例

代码示例来源:origin: jcustenborder/kafka-connect-spooldir

@Override
public long recordOffset() {
 return this.csvReader.getLinesRead();
}

代码示例来源:origin: jcustenborder/kafka-connect-spooldir

log.info("Found previous offset. Skipping {} line(s).", lastOffset.intValue());
String[] row = null;
while (null != (row = this.csvReader.readNext()) && this.csvReader.getLinesRead() < lastOffset) {
 log.trace("skipped row");

代码示例来源:origin: jcustenborder/kafka-connect-spooldir

if (log.isInfoEnabled() && this.csvReader.getLinesRead() % ((long) this.config.batchSize * 20) == 0) {
 log.info("Processed {} lines of {}", this.csvReader.getLinesRead(), this.fileMetadata);

代码示例来源:origin: com.opencsv/opencsv

private void submitAllBeans() throws IOException, InterruptedException {
  while (null != (line = csvReader.readNext())) {
    lineProcessed = csvReader.getLinesRead();
    executor.execute(new ProcessCsvLine<>(
        lineProcessed, mappingStrategy, filter, verifiers, line,
        resultantBeansQueue, thrownExceptionsQueue,
        throwExceptions));
  }
  // Normal termination
  executor.shutdown();
  executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); // Wait indefinitely
  if(accumulateThread != null) {
    accumulateThread.setMustStop(true);
    accumulateThread.join();
  }
  // There's one more possibility: The very last bean caused a problem.
  if(executor.getTerminalException() != null) {
    // Trigger a catch in the calling method
    throw new RejectedExecutionException();
  }
}

相关文章