本文整理汇总了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();
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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;
}
示例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));
}
}
示例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;
}
示例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;
}
示例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
}
示例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;
}