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

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

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

CSVReader.readAll介绍

[英]Reads the entire file into a List with each element being a String[] of tokens. Since the current implementation returns a java.util.LinkedList, you are strongly discouraged from using index-based access methods to get at items in the list. Instead, iterate over the list.
[中]将整个文件读入一个列表,每个元素都是一个令牌字符串[]。因为当前的实现返回一个java。util。LinkedList,强烈建议您不要使用基于索引的访问方法来获取列表中的项。相反,迭代列表。

代码示例

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

for (String[] line : csv.readAll()) {
  lineNo++;

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

int lineNo = 0;
try (BatchTransaction tx = new BatchTransaction(db, clc.getBatchSize(), reporter)) {
  for (String[] line : csv.readAll()) {
    lineNo++;

代码示例来源:origin: TGAC/miso-lims

public DelimitedSpreadsheetWrapper(InputStream in) throws IOException {
 try (CSVReader reader = new CSVReader(new InputStreamReader(in))) {
  this.rows = reader.readAll();
 }
}

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

csvReader = new CSVReader(fReader);
list = (ArrayList<String[]>) csvReader.readAll();
return list;

代码示例来源:origin: ExpediaDotCom/adaptive-alerting

/**
 * Loads a {@link MetricFrame} from a CSV input stream.
 *
 * @param metricDefinition The underlying metric.
 * @param in               CSV input stream.
 * @param hasHeader        Indicates whether the data has a header row.
 * @return A data frame containing the CSV data.
 * @throws IOException if there's a problem reading the CSV input stream.
 */
public static MetricFrame loadCsv(MetricDefinition metricDefinition, InputStream in, boolean hasHeader)
    throws IOException {
  
  List<String[]> rows;
  try (final BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
    final int skipLines = hasHeader ? 1 : 0;
    final CSVReader reader = new CSVReaderBuilder(br).withSkipLines(skipLines).build();
    rows = reader.readAll();
  }
  
  final int numRows = rows.size();
  final MetricData[] metricData = new MetricData[numRows];
  
  for (int i = 0; i < numRows; i++) {
    metricData[i] = toMetricData(metricDefinition, rows.get(i));
  }
  
  
  return new MetricFrame(metricData);
}

代码示例来源:origin: http-builder-ng/http-builder-ng

/**
 * Used to parse the server response content using the OpenCsv parser.
 *
 * @param config the configuration
 * @param fromServer the server content accessor
 * @return the parsed object
 */
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 TransportingException(e);
  }
}

代码示例来源:origin: io.github.http-builder-ng/http-builder-ng-core

/**
 * Used to parse the server response content using the OpenCsv parser.
 *
 * @param config the configuration
 * @param fromServer the server content accessor
 * @return the parsed object
 */
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 TransportingException(e);
  }
}

代码示例来源:origin: matsim-org/matsim

public static List<String[]> readFile(String file, char separator) {
    try (CSVReader reader = new CSVReaderBuilder(IOUtils.getBufferedReader(file))
        .withCSVParser(new CSVParserBuilder().withSeparator(separator).build()).build()) {
      return reader.readAll();
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }
}

代码示例来源:origin: EvoSuite/evosuite

List<String[]> rows = reader.readAll();
assertTrue(rows.size() == 2);
reader.close();

代码示例来源:origin: EvoSuite/evosuite

@Test
public void testCoveredGoalsCountCSV_SingleCriterion() throws IOException {
  EvoSuite evosuite = new EvoSuite();
  String targetClass = Calculator.class.getCanonicalName();
  Properties.TARGET_CLASS = targetClass;
  Properties.CRITERION = new Properties.Criterion[] {
    Properties.Criterion.WEAKMUTATION
  };
  Properties.OUTPUT_VARIABLES="TARGET_CLASS,criterion,Coverage,Covered_Goals,Total_Goals";
  Properties.STATISTICS_BACKEND = StatisticsBackend.CSV;
  String[] command = new String[] {
    "-class", targetClass,
    "-generateSuite"
  };
  Object result = evosuite.parseCommandLine(command);
  Assert.assertNotNull(result);
  String statistics_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR + File.separator + "statistics.csv";
  System.out.println("Statistics file " + statistics_file);
  CSVReader reader = new CSVReader(new FileReader(statistics_file));
  List<String[]> rows = reader.readAll();
  assertTrue(rows.size() == 2);
  reader.close();
  assertEquals(targetClass, rows.get(1)[0]); // TARGET_CLASS
  assertEquals("WEAKMUTATION", rows.get(1)[1]); // criterion
  assertEquals("1.0", rows.get(1)[2]); // Coverage
  assertEquals("48", rows.get(1)[3]); // Covered_Goals
  assertEquals("48", rows.get(1)[4]); // Total_Goals
}

代码示例来源:origin: EvoSuite/evosuite

@Test
public void testCoveredGoalsCountCSV_MultipleCriterion() throws IOException {
  EvoSuite evosuite = new EvoSuite();
  String targetClass = Calculator.class.getCanonicalName();
  Properties.TARGET_CLASS = targetClass;
  Properties.CRITERION = new Properties.Criterion[] {
    Properties.Criterion.BRANCH,
    Properties.Criterion.LINE,
    Properties.Criterion.ONLYMUTATION
  };
  Properties.OUTPUT_VARIABLES="TARGET_CLASS,criterion,Coverage,Covered_Goals,Total_Goals";
  Properties.STATISTICS_BACKEND = StatisticsBackend.CSV;
  String[] command = new String[] {
    "-class", targetClass,
    "-generateSuite"
  };
  Object result = evosuite.parseCommandLine(command);
  Assert.assertNotNull(result);
  String statistics_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR + File.separator + "statistics.csv";
  System.out.println("Statistics file " + statistics_file);
  CSVReader reader = new CSVReader(new FileReader(statistics_file));
  List<String[]> rows = reader.readAll();
  assertTrue(rows.size() == 2);
  reader.close();
  assertEquals(targetClass, rows.get(1)[0]); // TARGET_CLASS
  assertEquals("BRANCH;LINE;ONLYMUTATION", rows.get(1)[1]); // criterion
  assertEquals("1.0", rows.get(1)[2]); // Coverage
  assertEquals("58", rows.get(1)[3]); // Covered_Goals
  assertEquals("58", rows.get(1)[4]); // Total_Goals
}

代码示例来源:origin: EvoSuite/evosuite

List<String[]> rows = reader.readAll();
assertTrue(rows.size() == 2);
reader.close();

代码示例来源:origin: EvoSuite/evosuite

@Test
public void testCoveredGoalsCountCSV_SingleCriterionBranch_Enums() throws IOException {
  EvoSuite evosuite = new EvoSuite();
  String targetClass = PureEnum.class.getCanonicalName();
  Properties.TARGET_CLASS = targetClass;
  Properties.CRITERION = new Properties.Criterion[] {
    Properties.Criterion.BRANCH
  };
  Properties.OUTPUT_VARIABLES="TARGET_CLASS,criterion,Coverage,Covered_Goals,Total_Goals,BranchCoverage";
  Properties.STATISTICS_BACKEND = StatisticsBackend.CSV;
  String[] command = new String[] {
    "-class", targetClass,
    "-generateSuite"
  };
  Object result = evosuite.parseCommandLine(command);
  Assert.assertNotNull(result);
  String statistics_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR + File.separator + "statistics.csv";
  System.out.println("Statistics file " + statistics_file);
  CSVReader reader = new CSVReader(new FileReader(statistics_file));
  List<String[]> rows = reader.readAll();
  assertTrue(rows.size() == 2);
  reader.close();
  assertEquals(targetClass, rows.get(1)[0]); // TARGET_CLASS
  assertEquals("BRANCH", rows.get(1)[1]); // criterion
  assertEquals("1.0", rows.get(1)[2]); // Coverage
  assertEquals("0", rows.get(1)[3]); // Covered_Goals
  assertEquals("0", rows.get(1)[4]); // Total_Goals
  assertEquals("1.0", rows.get(1)[5]); // BranchCoverage
}

代码示例来源:origin: EvoSuite/evosuite

List<String[]> rows = reader.readAll();
assertTrue(rows.size() == 2);
reader.close();

代码示例来源:origin: EvoSuite/evosuite

@Test
public void testZeroRhoScoreWithoutPreviousCoverage() throws IOException {
  EvoSuite evosuite = new EvoSuite();
  String targetClass = Compositional.class.getCanonicalName();
  Properties.TARGET_CLASS = targetClass;
  Properties.OUTPUT_VARIABLES = RuntimeVariable.RhoScore.name();
  Properties.STATISTICS_BACKEND = StatisticsBackend.CSV;
  String[] command = new String[] {
    "-class", targetClass,
    "-generateTests"
  };
  Object result = evosuite.parseCommandLine(command);
  Assert.assertNotNull(result);
  List<?> goals = RhoCoverageFactory.getGoals();
  assertEquals(12, goals.size());
  String statistics_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR + File.separator + "statistics.csv";
  CSVReader reader = new CSVReader(new FileReader(statistics_file));
  List<String[]> rows = reader.readAll();
  assertTrue(rows.size() == 2);
  reader.close();
  assertEquals("0.5", rows.get(1)[0]);
}

代码示例来源:origin: EvoSuite/evosuite

List<String[]> rows = reader.readAll();
assertTrue(rows.size() == 2);
reader.close();

代码示例来源:origin: EvoSuite/evosuite

List<String[]> rows = reader.readAll();
assertTrue(rows.size() == 2);
reader.close();

相关文章