com.opencsv.CSVReader类的使用及代码示例

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

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

CSVReader介绍

[英]A very simple CSV reader released under a commercial-friendly license.
[中]一个非常简单的CSV阅读器,根据商业友好许可证发布。

代码示例

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

try (CSVReader csvr = new CSVReader(new StringReader(config.getString(path)));) {
 valueList = Lists.newArrayList(csvr.readNext());
} catch (IOException ioe) {
 throw new RuntimeException(ioe);

代码示例来源:origin: twosigma/beakerx

@Override
 public void close() throws Exception {
  reader.close();
 }
}

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

new CSVReader(new InputStreamReader(
             this.fileBasedExtractor.getFsHelper().getFileStream(file),
             ConfigurationKeys.DEFAULT_CHARSET_ENCODING), delimiter));
 } else {
  reader = this.fileBasedExtractor.getCloser().register(
    new CSVReader(new InputStreamReader(
             this.fileBasedExtractor.getFsHelper().getFileStream(file),
             ConfigurationKeys.DEFAULT_CHARSET_ENCODING)));
PeekingIterator<String[]> iterator = Iterators.peekingIterator(reader.iterator());

代码示例来源: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: metafacture/metafacture-core

private String[] parseCsv(final String string) {
  String[] parts = new String[0];
  try {
    final CSVReader reader = new CSVReader(new StringReader(string),
        separator);
    final List<String[]> lines = reader.readAll();
    if (lines.size() > 0) {
      parts = lines.get(0);
    }
    reader.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
  return parts;
}

代码示例来源:origin: twosigma/beakerx

public CSVIterator(String fileName) throws IOException {
 this(new CSVReader(new FileReader(fileName)));
}

代码示例来源: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

final CSVReader csv = new CSVReader(reader, clc.getDelimiter());
final String[] loadCsvCompatibleHeader = fields.stream().map(f -> f.getName()).toArray(String[]::new);
  for (String[] line : csv.readAll()) {
    lineNo++;

代码示例来源: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: uk.gov.dstl.baleen/baleen-jobs

/**
 * Read the CSV file and send interactions to the consumer
 *
 * @param consumer the consumer (first param is the InteractionRelation and the second the list of
 *     alternative words)
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void read(BiConsumer<InteractionDefinition, Collection<String>> consumer)
  throws IOException {
 try (CSVReader reader = new CSVReader(new FileReader(inputFilename))) {
  StreamSupport.stream(reader.spliterator(), false).forEach(r -> processRecord(r, consumer));
 }
}

代码示例来源: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: 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();
  }
}

代码示例来源:origin: org.codehaus.groovy.modules/http-builder-ng-core

public static Object parse(final ChainedHttpConfig config, final FromServer fromServer) {
  try {
    final Csv.Context ctx = (Csv.Context) config.actualContext(fromServer.getContentType(), Csv.Context.ID);
    return ctx.makeReader(fromServer.getReader()).readAll();
  }
  catch(IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: com.ksc.mission.base/file

public CloseableReader(CSVReader reader) {
  iteratorSupplier = () -> reader.iterator();
  closer = () -> { 
    try {
      reader.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  };
}

代码示例来源:origin: twosigma/beakerx

CSVIterator(CSVReader csvReader) {
 reader = csvReader;
 rows = reader.iterator();
 header = rows.next();
}

代码示例来源: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: Cloudslab/cloudsim

public CostumeCSVReader(File inputFile) {
    // TODO Auto-generated method stub
    CSVReader reader = null;
    try 
    {
//            Log.printLine(inputFile);
      //Get the CSVReader instance with specifying the delimiter to be used
      reader = new CSVReader(new FileReader(inputFile));
      fileData= reader.readAll();
      
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally	{
      try {
        reader.close();
      } catch (IOException e) {
        e.printStackTrace();
      }

  }
}

代码示例来源:origin: twosigma/beakerx

public Iterable<Map<String, Object>> readIterable(String fileName) throws IOException {
 CSVReader reader = new CSVReader(new FileReader(fileName));
 return () -> new CSVIterator(reader);
}

代码示例来源: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

final CSVReader csv = new CSVReader(reader, clc.getDelimiter(), clc.getQuotationCharacter());
  for (String[] line : csv.readAll()) {
    lineNo++;

相关文章