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

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

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

CSVReader.readNext介绍

[英]Reads the next line from the buffer and converts to a string array.
[中]从缓冲区读取下一行并转换为字符串数组。

代码示例

代码示例来源:origin: apache/incubator-gobblin

valueList = Lists.newArrayList(csvr.readNext());
} catch (IOException ioe) {
 throw new RuntimeException(ioe);

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

public CSVSpliterator(CSVReader csv, String[] header, String url, long skip, long limit, boolean ignore, Map<String, Mapping> mapping, List<String> nullValues, EnumSet<Results> results) throws IOException {
  super(Long.MAX_VALUE, Spliterator.ORDERED);
  this.csv = csv;
  this.header = header;
  this.url = url;
  this.ignore = ignore;
  this.mapping = mapping;
  this.nullValues = nullValues;
  this.results = results;
  this.limit = skip + limit;
  lineNo = skip;
  while (skip-- > 0) {
    csv.readNext();
  }
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

private String[] getHeader(boolean hasHeader, CSVReader csv, List<String> ignore, Map<String, Mapping> mapping) throws IOException {
  if (!hasHeader) return null;
  String[] header = csv.readNext();
  if (ignore.isEmpty()) return header;
  for (int i = 0; i < header.length; i++) {
    if (ignore.contains(header[i]) || mapping.getOrDefault(header[i], Mapping.EMPTY).ignore) {
      header[i] = null;
    }
  }
  return header;
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Override
  public boolean tryAdvance(Consumer<? super CSVResult> action) {
    try {
      String[] row = csv.readNext();
      if (row != null && lineNo < limit) {
        action.accept(new CSVResult(header, row, lineNo++, ignore,mapping, nullValues,results));
        return true;
      }
      return false;
    } catch (IOException e) {
      throw new RuntimeException("Error reading CSV from URL " + cleanUrl(url) + " at " + lineNo, e);
    }
  }
}

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

/**
 * Skip a given number of lines.
 * @param numberOfLinesToSkip The number of lines to skip
 * @since 4.2
 * @throws IOException If anything bad happens when reading the file
 */
public void skip(int numberOfLinesToSkip) throws IOException {
  for (int j = 0; j < numberOfLinesToSkip; j++) {
      readNext();
  }
}

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

/**
* @param reader Reader for the CSV data.
* @throws IOException If unable to read data from the reader.
*/
public CSVIterator(CSVReader reader) throws IOException {
 this.reader = reader;
 nextLine = reader.readNext();
}

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

/**
   * Returns the next line from the input without removing it from the
   * CSVReader.
   * Subsequent calls to this method will continue to return the same line
   * until a call is made to {@link #readNext()} or any other method that
   * advances the cursor position in the input. The first call to
   * {@link #readNext()} after calling this method will return the same line
   * this method does.
   * 
   * @return The next line from the input, or null if there are no more lines
   * @throws IOException If bad things happen during the read operation
   * @since 4.2
   */
  public String[] peek() throws IOException {
    if(peekedLine == null) {
      peekedLine = readNext();
    }
    return peekedLine;
  }
}

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

private void initializeHeader() throws IOException {
  String[] headers = super.readNext();
  for (int i = 0; i < headers.length; i++) {
    headerIndex.put(headers[i], i);
  }
}

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client

@Override
public void captureHeader(CSVReader reader) throws IOException {
  // header is mandatory in SPARQL CSV
  bindingNames = Arrays.asList(reader.readNext());
}

代码示例来源:origin: eclipse/rdf4j

@Override
public void captureHeader(CSVReader reader) throws IOException {
  // header is mandatory in SPARQL CSV
  bindingNames = Arrays.asList(reader.readNext());
}

代码示例来源:origin: eclipse/rdf4j

@Override
public void captureHeader(CSVReader reader) throws IOException {
  // header is mandatory in SPARQL TSV
  bindingNames = Stream.of(reader.readNext())
      .map(s -> StringUtils.removeStart(s, "?"))
      .collect(Collectors.toList());
}

代码示例来源:origin: md-5/SpecialSource

private void readIntoMap(File file, Map<String, String> map) throws IOException {
  try (FileReader fileReader = new FileReader(file);
     CSVReader csvReader = new CSVReader(fileReader)) {
    String[] line;
    while ((line = csvReader.readNext()) != null) {
      if (line.length == 0) {
        continue;
      }
      Preconditions.checkArgument(line.length >= 2, "Invalid csv line: %s", (Object) line);
      map.put(line[0], line[1]);
    }
  }
}

代码示例来源:origin: kakao/hbase-tools

private void readHeader(CSVReader reader, List<LoadEntry> savedLoadEntryList) throws IOException {
  String[] nextLine;
  nextLine = reader.readNext();
  for (String string : nextLine) {
    try {
      savedLoadEntryList.add(LoadEntry.valueOf(string));
    } catch (Exception ignored) {
    }
  }
}

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

/**
*
* Returns the next element in the iterator.
*
* @return The next element of the iterator.
*/
@Override
public String[] next() {
 String[] temp = nextLine;
 try {
   nextLine = reader.readNext();
 } catch (IOException e) {
   NoSuchElementException nse = new NoSuchElementException(e.getLocalizedMessage());
   nse.initCause(e);
   throw nse;
 }
 return temp;
}

代码示例来源:origin: io.github.therealmone/TranslatorAPI

public static void loadAnalyzeTable(InputStream is) {
  analyzeTable = new HashMap<>();
  try {
    CSVReader csvReader = new CSVReader(new InputStreamReader(is));
    String[] description = csvReader.readNext();
    String[] nextLine;
    while ((nextLine = csvReader.readNext()) != null) {
      Map<String, Integer> tmp = new HashMap<>();
      for (int i = 1; i < nextLine.length; i++) {
        tmp.put(description[i], Integer.parseInt(nextLine[i]));
      }
      analyzeTable.put(nextLine[0], tmp);
    }
    csvReader.close();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: io.github.therealmone/TranslatorAPI

public static void loadLangRules(InputStream is) {
  langRules = new HashMap<>();
  try {
    CSVReader csvReader = new CSVReader(new InputStreamReader(is));
    String[] nextLine;
    csvReader.readNext();
    while ((nextLine = csvReader.readNext()) != null) {
      try {
        langRules.put(Integer.parseInt(nextLine[0].trim()), nextLine[2].split("\\s\\+\\s"));
      } catch (NumberFormatException e) {
        e.printStackTrace();
      }
    }
    csvReader.close();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: io.mindmaps/migration-csv

/**
 * Convert native data format (CSVReader) to stream of templates
 * @param template parametrized graql insert query
 * @param reader CSV reader of data file
 * @return Stream of data migrated into templates
 * @throws IOException
 */
private Stream<String> resolve(String template, CSVReader reader) throws IOException {
  String[] header = reader.readNext();
  return partitionedStream(reader.iterator())
      .map(batch -> batchParse(header, batch))
      .map(data -> template(template, data));
}

代码示例来源:origin: tarql/tarql

@Override
public Binding next() {
  Binding current = binding;
  binding = null;
  String[] row;
  try {
    while ((row = csv.readNext()) != null) {
      // Skip rows without data
      if (isEmpty(row))
        continue;
      binding = toBinding(row);
      rownum++;
      break;
    }
  } catch (IOException e) {
    throw new TarqlException(e);
  }
  return current;
}

代码示例来源:origin: org.apache.metamodel/MetaModel-csv

private List<Column> buildColumns() {
  CSVReader reader = null;
  try {
    reader = _schema.getDataContext().createCsvReader(0);
    final int columnNameLineNumber = _schema.getDataContext().getConfiguration().getColumnNameLineNumber();
    for (int i = 1; i < columnNameLineNumber; i++) {
      reader.readNext();
    }
    final List<String> columnHeaders = Arrays.asList(Optional.ofNullable(reader.readNext()).orElse(new String[0]));
    reader.close();
    return buildColumns(columnHeaders);
  } catch (IOException e) {
    throw new IllegalStateException("Exception reading from resource: "
        + _schema.getDataContext().getResource().getName(), e);
  } finally {
    FileHelper.safeClose(reader);
  }
}

代码示例来源:origin: apache/metamodel

private List<Column> buildColumns() {
  CSVReader reader = null;
  try {
    reader = _schema.getDataContext().createCsvReader(0);
    final int columnNameLineNumber = _schema.getDataContext().getConfiguration().getColumnNameLineNumber();
    for (int i = 1; i < columnNameLineNumber; i++) {
      reader.readNext();
    }
    final List<String> columnHeaders = Arrays.asList(Optional.ofNullable(reader.readNext()).orElse(new String[0]));
    reader.close();
    return buildColumns(columnHeaders);
  } catch (IOException e) {
    throw new IllegalStateException("Exception reading from resource: "
        + _schema.getDataContext().getResource().getName(), e);
  } finally {
    FileHelper.safeClose(reader);
  }
}

相关文章