當前位置: 首頁>>代碼示例>>Java>>正文


Java CSVReader.readAll方法代碼示例

本文整理匯總了Java中com.opencsv.CSVReader.readAll方法的典型用法代碼示例。如果您正苦於以下問題:Java CSVReader.readAll方法的具體用法?Java CSVReader.readAll怎麽用?Java CSVReader.readAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.opencsv.CSVReader的用法示例。


在下文中一共展示了CSVReader.readAll方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: importCSV

import com.opencsv.CSVReader; //導入方法依賴的package包/類
public static void importCSV(String csv, boolean cleanBeforeImport) {
    LOG.info("Importing CSV. Cleanup old data before import: {}", cleanBeforeImport);
    CSVReader csvReader = CSVUtils.createDefaultReader(csv);
    try {
        if (cleanBeforeImport) {
            ElasticSearch.getNamedQueryOperations().deleteAll();
        }
        List<String[]> data = csvReader.readAll();
        Map<String, Integer> columnIndexes = CSVUtils.resolveColumnIndexes(CSV_COLUMNS, data.get(0));
        data.stream()
                .skip(1)
                .map(row -> mapCsvRowToNamedQuery(row, columnIndexes))
                .forEach(nq -> ElasticSearch.getNamedQueryOperations().save(nq));
        LOG.info("Imported {} rows", data.size() - 1);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:tokenmill,項目名稱:crawling-framework,代碼行數:19,代碼來源:NamedQueryImportExport.java

示例2: importCSV

import com.opencsv.CSVReader; //導入方法依賴的package包/類
public static void importCSV(String csv, boolean cleanBeforeImport) {
    LOG.info("Importing CSV. Cleanup old data before import: {}", cleanBeforeImport);
    CSVReader csvReader = CSVUtils.createDefaultReader(csv);
    try {
        if (cleanBeforeImport) {
            ElasticSearch.getHttpSourceOperations().deleteAll();
        }
        List<String[]> data = csvReader.readAll();
        String[] headerLine = data.get(0);
        Map<String, Integer> columnIndexes = resolveColumnIndexes(headerLine, CSV_COLUMNS);
        data.stream()
                .skip(1)
                .map(row -> mapCsvRowToHttpSource(row, columnIndexes))
                .forEach(hs -> ElasticSearch.getHttpSourceOperations().save(hs));
        LOG.info("Imported {} rows", data.size() - 1);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:tokenmill,項目名稱:crawling-framework,代碼行數:20,代碼來源:HttpSourceImportExport.java

示例3: importCSV

import com.opencsv.CSVReader; //導入方法依賴的package包/類
public static void importCSV(String csv, boolean cleanBeforeImport) {
    LOG.info("Importing CSV. Cleanup old data before import: {}", cleanBeforeImport);
    CSVReader csvReader = CSVUtils.createDefaultReader(csv);
    try {
        if (cleanBeforeImport) {
            ElasticSearch.getHttpSourceTestOperations().deleteAll();
        }
        List<String[]> data = csvReader.readAll();
        String[] headerLine = data.get(0);
        Map<String, Integer> columnIndexes = resolveColumnIndexes(headerLine, CSV_COLUMNS);
        data.stream()
                .skip(1)
                .map(row -> mapCsvRowToHttpSourceTest(row, columnIndexes))
                .forEach(hst -> ElasticSearch.getHttpSourceTestOperations().save(hst));
        LOG.info("Imported {} rows", data.size() - 1);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:tokenmill,項目名稱:crawling-framework,代碼行數:20,代碼來源:HttpSourceTestImportExport.java

示例4: readLine

import com.opencsv.CSVReader; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public String[] readLine(int line, boolean readResult) {
    logger.debug("readLine at line {}", line);
    try {
        CSVReader reader = openInputData();
        List<String[]> a = reader.readAll();
        if (line >= a.size()) {
            return null;
        }
        String[] row = a.get(line);
        if ("".equals(row[0])) {
            return null;
        } else {
            String[] ret = readResult ? new String[columns.size()] : new String[columns.size() - 1];
            for (int i = 0; i < ret.length; i++) {
                ret[i] = row[i];
            }
            return ret;
        }
    } catch (IOException e) {
        logger.error("error CsvDataProvider.readLine()", e);
        return null;
    }
}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:28,代碼來源:CsvDataProvider.java

示例5: parseUrlATMO

import com.opencsv.CSVReader; //導入方法依賴的package包/類
public static PointMesure[] parseUrlATMO(URL url) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    CSVReader reader = new CSVReader(in,';');

    List<String[]> contenuCsv = reader.readAll();

    String[] date = contenuCsv.get(0);
    String[] indice = contenuCsv.get(1);

    PointMesure[] PointMesures = new PointMesure[indice.length];

    for (int i = 0; i < PointMesures.length ; i++) {
        PointMesures[i] = new PointMesure(date[i], indice[i]);
    }

    //inverser les éléments du tableau
    for(int i = 0; i < PointMesures.length / 2; i++)
    {
        PointMesure temp = PointMesures[i];
        PointMesures[i] = PointMesures[PointMesures.length - i - 1];
        PointMesures[PointMesures.length - i - 1] = temp;
    }

    return PointMesures;
}
 
開發者ID:MadiBreizh,項目名稱:ATMO972,代碼行數:26,代碼來源:Utilites.java

示例6: DataSet

import com.opencsv.CSVReader; //導入方法依賴的package包/類
DataSet(String filePath) {
    this.attributes = new String[0];
    this.data = new ArrayList<>();
    try {
        CSVReader csvReader = new CSVReader(new BufferedReader(new FileReader(filePath)));
        List<String[]> records = csvReader.readAll();
        if (records == null || records.isEmpty()) {
            return;
        }
        this.attributesCount = records.get(0).length;
        attributeDistinctValues = new ArrayList<>();
        for (int i = 0; i < attributesCount; i++) {
            attributeDistinctValues.add(new HashSet<>());
        }
        this.attributes = Arrays.copyOf(records.get(0), attributesCount);
        this.targetAttribute = this.attributesCount - 1;
        records.remove(0);
        this.data = new ArrayList<>(records);
        for (String[] row : data) {
            for (int j = 0; j < row.length; j++) {
                attributeDistinctValues.get(j).add(row[j]);
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Unable to open file: " + filePath + ", exiting!");
        System.exit(1);
    }
}
 
開發者ID:MarkXLII,項目名稱:CS-436_580L_Introduction-to-Machine-Learning,代碼行數:31,代碼來源:DataSet.java

示例7: DataSet

import com.opencsv.CSVReader; //導入方法依賴的package包/類
public DataSet(String filePath) {
    this.attributes = new String[0];
    this.data = new ArrayList<>();
    try {
        CSVReader csvReader = new CSVReader(new BufferedReader(new FileReader(filePath)));
        List<String[]> records = csvReader.readAll();
        if (records == null || records.isEmpty()) {
            return;
        }
        this.attributesCount = records.get(0).length;
        attributeDistinctValues = new ArrayList<>();
        for (int i = 0; i < attributesCount; i++) {
            attributeDistinctValues.add(new HashSet<>());
        }
        this.attributes = Arrays.copyOf(records.get(0), attributesCount);
        this.targetAttribute = this.attributesCount - 1;
        records.remove(0);
        this.data = new ArrayList<>(records);
        for (String[] row : data) {
            for (int j = 0; j < row.length; j++) {
                attributeDistinctValues.get(j).add(row[j]);
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Unable to open file: " + filePath + ", exiting!");
        System.exit(1);
    }
}
 
開發者ID:MarkXLII,項目名稱:CS-436_580L_Introduction-to-Machine-Learning,代碼行數:31,代碼來源:DataSet.java

示例8: writeValue

import com.opencsv.CSVReader; //導入方法依賴的package包/類
private void writeValue(String column, int line, String value) {
    logger.debug("Writing: [{}] at line [{}] in column [{}]", value, line, column);
    int colIndex = columns.indexOf(column);
    CSVReader reader;
    try {
        reader = openOutputData();
        List<String[]> csvBody = reader.readAll();
        csvBody.get(line)[colIndex] = value;
        reader.close();
        writeValue(column, line, value, csvBody);
    } catch (IOException e1) {
        logger.error(Messages.getMessage(CSV_DATA_PROVIDER_WRITING_IN_CSV_ERROR_MESSAGE), column, line, value, e1);
    }
}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:15,代碼來源:CsvDataProvider.java

示例9: getRecords

import com.opencsv.CSVReader; //導入方法依賴的package包/類
/**
 * Parses a csv file.
 * @param inputStreamReader The browscap.csv file as a InputStreamReader object.
 * @return a List of String arrays,where a String array represents one csv record.
 * @throws IOException
 */
private List<String[]> getRecords(final InputStreamReader inputStreamReader) throws IOException {
	final CSVReader csvReader = new CSVReader(inputStreamReader);
	final List<String[]> records = csvReader.readAll();
	csvReader.close();
	//Different versions of the Csv file have different headers.
	//We consider that each record is a String array ,where each array contains atleast 43 records.
	return records.stream()
			.filter( record -> record.length > 43 )
			.collect(Collectors.toList());
}
 
開發者ID:ankushs92,項目名稱:Browscap4j,代碼行數:17,代碼來源:CsvParsingService.java

示例10: fileToRecords

import com.opencsv.CSVReader; //導入方法依賴的package包/類
public <T extends Record> List<T> fileToRecords(String filePath, Class<T> recordType) throws FileNotFoundException, IOException, InstantiationException, IllegalAccessException {

        CSVReader reader = new CSVReader(new FileReader(filePath), ',', '\"');
        List<String[]> lines = reader.readAll();

        List<String> headers = Arrays.asList(lines.get(0));
        List<Integer> keyPositions = getKeyPositions(headers, keys);
        int displayIdPosition = getDisplayIdPosition(headers, displayId);
        List<T> records = new ArrayList<>();

        for (int i = 1; i < lines.size(); i++) {
            String[] line = lines.get(i);

            T record = recordType.newInstance();

            record.setDisplayId(line[displayIdPosition]);

            String key = getKey(keyPositions, line);
            record.setKey(key);

            record.setRecordId(UUID.randomUUID().toString());

            String json = getJson(headers, line);
            DBObject dBObject = (DBObject) JSON.parse(json);
            record.setdBObject(dBObject);
            record.setMatchName(matchName);

            record.setMatchMetadata(new MatchMetadata());
            record.getMatchMetadata().setStatus(Constants.MatchingStatus.UnMatch.name());

            records.add(record);
        }

        return records;
    }
 
開發者ID:nimesh-mittal,項目名稱:elastic-match,代碼行數:36,代碼來源:CSVDataImporter.java

示例11: parseFile

import com.opencsv.CSVReader; //導入方法依賴的package包/類
private void parseFile(FileParserMessage<DataFileColumn> msg, CSVReader csvReader, Boolean readFirstColumnAsColumnName) throws IOException {
    List<String[]> allDataInFile = csvReader.readAll();
    String[] header = null;
    Integer typeColumnIndex = readFirstColumnAsColumnName ? headerColumnIndex + 1 : 0;
    if (readFirstColumnAsColumnName) {
        header = getSeparatedValue(allDataInFile.get(headerColumnIndex));
    }
    String[] columnType = getSeparatedValue(allDataInFile.get(typeColumnIndex));
    List<String[]> data = allDataInFile.subList(typeColumnIndex + 1, allDataInFile.size());
    if (validate(msg, columnType, data)) {
        msg.setData(prepareData(msg, header, columnType, data));
    }
}
 
開發者ID:abixen,項目名稱:abixen-platform,代碼行數:14,代碼來源:CsvParserServiceImpl.java

示例12: readInfluxdbV1HttpOutputModules

import com.opencsv.CSVReader; //導入方法依賴的package包/類
private static List<InfluxdbV1HttpOutputModule> readInfluxdbV1HttpOutputModules() {
    
    List<InfluxdbV1HttpOutputModule> influxdbV1HttpOutputModules = new ArrayList<>();
    
    for (int i = -1; i < 10000; i++) {
        String influxdbV1HttpOutputModuleKey = "influxdb_v1_output_module_" + (i + 1);
        String influxdbV1HttpOutputModuleValue = applicationConfiguration_.safeGetString(influxdbV1HttpOutputModuleKey, null);
        
        if (influxdbV1HttpOutputModuleValue == null) continue;
        
        try {
            CSVReader reader = new CSVReader(new StringReader(influxdbV1HttpOutputModuleValue));
            List<String[]> csvValuesArray = reader.readAll();

            if ((csvValuesArray != null) && !csvValuesArray.isEmpty() && (csvValuesArray.get(0) != null)) {
                String[] csvValues = csvValuesArray.get(0);

                if (csvValues.length == 4) {                                
                    boolean isOutputEnabled = Boolean.valueOf(csvValues[0]);
                    String url = csvValues[1];
                    int numSendRetryAttempts = Integer.valueOf(csvValues[2]);
                    int maxMetricsPerMessage = Integer.valueOf(csvValues[3]);
                    
                    String uniqueId = "InfluxDB-V1-" + (i+1);

                    InfluxdbV1HttpOutputModule influxdbV1HttpOutputModule = new InfluxdbV1HttpOutputModule(isOutputEnabled, url, 
                            numSendRetryAttempts, maxMetricsPerMessage, uniqueId);
                    
                    influxdbV1HttpOutputModules.add(influxdbV1HttpOutputModule);
                }
            }
        }
        catch (Exception e) {
            logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        }
    }
    
    return influxdbV1HttpOutputModules;
}
 
開發者ID:PearsonEducation,項目名稱:StatsAgg,代碼行數:40,代碼來源:ApplicationConfiguration.java

示例13: readCustomActionUrls

import com.opencsv.CSVReader; //導入方法依賴的package包/類
private static List<HttpLink> readCustomActionUrls() {
    
    List<HttpLink> customActionUrls = new ArrayList<>();
    
    for (int i = 0; i < 1000; i++) {
        String customActionUrlKey = "custom_action_url_" + (i + 1);
        String customActionUrlValue = applicationConfiguration_.safeGetString(customActionUrlKey, null);
        
        if (customActionUrlValue == null) continue;
        
        try {
            CSVReader reader = new CSVReader(new StringReader(customActionUrlValue));
            List<String[]> csvValuesArray = reader.readAll();

            if ((csvValuesArray != null) && !csvValuesArray.isEmpty() && (csvValuesArray.get(0) != null)) {
                String[] csvValues = csvValuesArray.get(0);

                if (csvValues.length == 2) {                                
                    String url = csvValues[0];
                    String linkText = csvValues[1];
                    
                    HttpLink httpLink = new HttpLink(url, linkText);
                    customActionUrls.add(httpLink);
                }

            }
        }
        catch (Exception e) {
            logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        }
        
    }
    
    return customActionUrls;
}
 
開發者ID:PearsonEducation,項目名稱:StatsAgg,代碼行數:36,代碼來源:ApplicationConfiguration.java

示例14: testCoveredGoalsCountCSV_SingleCriterionBranch_Enums

import com.opencsv.CSVReader; //導入方法依賴的package包/類
@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
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:38,代碼來源:CoveredGoalsCountSystemTest.java

示例15: getData

import com.opencsv.CSVReader; //導入方法依賴的package包/類
/**
 * Gets data from csv file via OpenCSV api
 * @param csv_file csv file path
 * @return Returns list of string arrays for each line
 * @throws IOException
 */
public static List<String[]> getData(String csv_file) throws IOException {
	CSVReader reader = new CSVReader(new FileReader(csv_file));
	List<String[]> data = reader.readAll();
	reader.close();
	return data;
}
 
開發者ID:Anish2,項目名稱:CSV-to-XML-Converter,代碼行數:13,代碼來源:Converter.java


注:本文中的com.opencsv.CSVReader.readAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。