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

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

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

CSVReader.close介绍

[英]Closes the underlying reader.
[中]关闭基础读取器。

代码示例

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

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

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

@Override
public void close() {
  try {
    csv.close();
  } 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: 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: 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.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: 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: ontodev/robot

private static List<List<String>> readXSV(Reader reader, char separator) throws IOException {
 CSVReader csv =
   new CSVReaderBuilder(reader)
     .withCSVParser(new CSVParserBuilder().withSeparator(separator).build())
     .build();
 List<List<String>> rows = new ArrayList<>();
 for (String[] nextLine : csv) {
  rows.add(new ArrayList<>(Arrays.asList(nextLine)));
 }
 csv.close();
 return rows;
}

代码示例来源:origin: org.arrahtec/osdq-core

reader.close();
} catch (IOException ie) {
  System.out.println("\n IO Error:" + ie.getMessage());

代码示例来源:origin: org.datavec/datavec-dataframe

public static void append(String fileName, final CSVWriter writer, char columnSeparator, boolean skipHeader) {

    CSVReader reader = null;
    try {
      reader = new CSVReader(new FileReader(fileName), columnSeparator);
      if (skipHeader) { // skip the header
        reader.readNext();
      }
      String[] nextLine;
      while ((nextLine = reader.readNext()) != null) {
        writer.writeNext(nextLine);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
}

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

代码示例来源:origin: usc-isi-i2/Web-Karma

delimiterChar);
rowValues = reader.readNext();
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

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

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

@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();

相关文章