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


Java CsvListReader.read方法代碼示例

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


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

示例1: getAggregatedCstStatistic

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
static Statistics getAggregatedCstStatistic(final Collection<File> csv_files, CellProcessor[] processors, Integer column_index, boolean header) throws IOException {

        final Statistics statistics = new Statistics();
        for (File csv : csv_files) {
            final CsvListReader reader = getCsvListReader(csv, header);
            try {
                List<Object> row;
                while ((row = reader.read(processors)) != null) {
                    statistics.addSample((Number) row.get(column_index));
                }
            }
            finally {
                IOUtils.closeQuietly(reader);
            }
        }

        return statistics;
    }
 
開發者ID:stacs-srg,項目名稱:shabdiz,代碼行數:19,代碼來源:AnalyticsUtil.java

示例2: getAllDataType

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
private void getAllDataType(CsvListReader listReader)
{
	List<String> instances;
	try {
		instances = listReader.read();
		while((instances = listReader.read()) != null)
		{
			for(int i = 0; i < header.length; i++)
			{
				if(instances.get(i) != null)
				{
					String type = new String(determineProcessor(instances.get(i)));
					dataType.get(header[i]).get("AllDataTypes").add(type);
					dataType.get(header[i]).get("AllowedDataTypes").add(type);
				}
			}
		}
	} catch (IOException e) {
		// TODO Auto-generated catch block
		log.error( e );
	}
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:23,代碼來源:CSVMetamodelBuilder.java

示例3: testSkipCommentLines

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
@Test
public void testSkipCommentLines() throws IOException {
	String csv = "<!--Sarah,Connor-->\r\nJohn,Connor\r\n<!--Kyle,Reese-->";
	
	CsvPreference customPreference = new Builder(STANDARD_PREFERENCE).skipComments(new CommentMatches("<!--.*-->"))
		.build();
	CsvListReader listReader = new CsvListReader(new StringReader(csv), customPreference);
	List<String> line = listReader.read();
	List<String> emptyLine = listReader.read();
	
	Assert.assertNotNull(line);
	Assert.assertEquals(2, line.size());
	Assert.assertEquals("John", line.get(0));
	Assert.assertEquals("Connor", line.get(1));
	Assert.assertNull(emptyLine);
}
 
開發者ID:super-csv,項目名稱:super-csv,代碼行數:17,代碼來源:ReadingFeaturesTest.java

示例4: run

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
public void run() throws IOException {
	init();
	BufferedReader r = new BufferedReader(new FileReader(inputFile), 64*1024);
	CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
	BufferedWriter w = new BufferedWriter(new FileWriter(outputFile), 64*1024);
	CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
	List<String> line = csvReader.read();
	int col;
	if (colIndexOrName.matches("[0-9]+")) {
		col = Integer.parseInt(colIndexOrName);
	} else {
		col = line.indexOf(colIndexOrName);
	}
	line.add(newColName);
	csvWriter.write(line);
	while ((line = csvReader.read()) != null) {
		if (line.get(col).matches(regex)) {
			line.add("1");
		} else {
			line.add("0");
		}
		csvWriter.write(line);
	}
	csvReader.close();
	csvWriter.close();
}
 
開發者ID:tkuhn,項目名稱:memetools,代碼行數:27,代碼來源:ApplyRegex.java

示例5: readCSVFile

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
/**
 * 
 * @param file
 * @return
 * @throws java.io.IOException
 */
private static List<List<String>> readCSVFile(File file) throws IOException {
	List<List<String>> list = new ArrayList<List<String>>();

	CsvListReader csvReader = new CsvListReader(new BufferedReader(
			new InputStreamReader(new FileInputStream(file),
					Charset.forName("UTF-8"))),
			CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);

	List<String> line;
	while (null != (line = csvReader.read())) {
		List<String> temp = new ArrayList<String>();
		temp.addAll(line);
		list.add(temp);
	}
	csvReader.close();

	return list;
}
 
開發者ID:GreenDelta,項目名稱:olca-converter,代碼行數:25,代碼來源:ES2MappingFileUtil.java

示例6: loadTerms

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
private void loadTerms() throws IOException {
	log("Loading terms from " + termFile + "...");
	BufferedReader r = new BufferedReader(new FileReader(termFile));
	CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
	List<String> firstLine = csvReader.read();
	int col;
	if (colIndexOrName.matches("[0-9]+")) {
		col = Integer.parseInt(colIndexOrName);
	} else {
		col = firstLine.indexOf(colIndexOrName);
	}
	List<String> l;
	while ((l = csvReader.read()) != null) {
		terms.put(l.get(col), true);
	}
	csvReader.close();
	log("Number of terms loaded: " + terms.size());
}
 
開發者ID:tkuhn,項目名稱:memetools,代碼行數:19,代碼來源:DetectJournalTerms.java

示例7: readTermsCsv

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
private void readTermsCsv() throws IOException {
	BufferedReader r = new BufferedReader(new FileReader(termsFile));
	CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
	List<String> header = csvReader.read();
	int col;
	if (termCol.matches("[0-9]+")) {
		col = Integer.parseInt(termCol);
	} else {
		col = header.indexOf(termCol);
	}
	List<String> line;
	while ((line = csvReader.read()) != null) {
		String term = MemeUtils.normalize(line.get(col));
		terms.add(term);
		termFreq.put(term, 0);
		termCommFreq.put(term, new HashMap<String,Integer>());
		if (termCount >= 0 && terms.size() >= termCount) {
			break;
		}
	}
	csvReader.close();
}
 
開發者ID:tkuhn,項目名稱:memetools,代碼行數:23,代碼來源:CalculateCommData.java

示例8: readTermsCsv

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
private void readTermsCsv() throws IOException {
	BufferedReader r = new BufferedReader(new FileReader(termsFile));
	CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
	List<String> header = csvReader.read();
	int col;
	if (termCol.matches("[0-9]+")) {
		col = Integer.parseInt(termCol);
	} else {
		col = header.indexOf(termCol);
	}
	List<String> line;
	while ((line = csvReader.read()) != null) {
		String term = MemeUtils.normalize(line.get(col));
		terms.add(term);
		if (termCount >= 0 && terms.size() >= termCount) {
			break;
		}
	}
	csvReader.close();
}
 
開發者ID:tkuhn,項目名稱:memetools,代碼行數:21,代碼來源:CalculateFMatrices.java

示例9: readTerms

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
private void readTerms() throws IOException {
	BufferedReader r = new BufferedReader(new FileReader(inputFile), 64*1024);
	CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
	List<String> line = csvReader.read();
	int termCol = getColumnIndex(termColIndexOrName, line);
	int weightCol = getColumnIndex(weightColIndexOrName, line);
	while ((line = csvReader.read()) != null) {
		int weight = 1;
		if (weightCol > -1) weight = Integer.parseInt(line.get(weightCol));
		String term = line.get(termCol);
		if (firstTerms) {
			if (duplicatesMap.containsKey(term)) continue;
			if (count >= n) break;
			count++;
			list.add(term);
			if (!duplicatesAllowed) {
				duplicatesMap.put(term, true);
			}
		} else {
			totalWeights += weight;
			map.put(totalWeights, term);
		}
	}
	csvReader.close();
}
 
開發者ID:tkuhn,項目名稱:memetools,代碼行數:26,代碼來源:ExportTerms.java

示例10: parseSuperCSV

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
@Benchmark
public int parseSuperCSV(final Blackhole bh) throws Exception {
    final BufferedReader in = getReader();
    
    final CsvListReader reader = new CsvListReader(in, CsvPreference.STANDARD_PREFERENCE);

    int count = 0;
    List<String> record = null;
    while ((record = reader.read()) != null) {
        count++;
    }

    bh.consume(count);
    in.close();
    return count;
}
 
開發者ID:apache,項目名稱:commons-csv,代碼行數:17,代碼來源:CSVBenchmark.java

示例11: readPrimerMap

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
public static Map<String, String> readPrimerMap(String fileName) throws IOException {
	Map<String, String> primerMap = new HashMap<>();
	CsvListReader csvListReader = new CsvListReader(new BufferedReader(new FileReader(fileName)),
			CsvPreference.TAB_PREFERENCE);
	List<String> columns;
	while ((columns = csvListReader.read()) != null) {
		if (columns.size() == 2) {
			if (!primerMap.containsKey(columns.get(0))) {
				primerMap.put(columns.get(0), columns.get(1));
			} else {
				throw new RuntimeException("duplicate key in line:" + csvListReader.getLineNumber());
			}
		} else {
			throw new RuntimeException("column number incorrect in line:" + csvListReader.getLineNumber());
		}
	}
	csvListReader.close();
	return primerMap;
}
 
開發者ID:lancelothk,項目名稱:BSPAT,代碼行數:20,代碼來源:AttachPrimer.java

示例12: Iterator

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
public Iterator() {
	try {
		FileReader core = new FileReader(source);
		//Get to the first record-start in the segment
		core.skip(segStart);
		CsvPreference pref = new CsvPreference.Builder('"', delimiter, CsvPreference.STANDARD_PREFERENCE.getEndOfLineSymbols()).build();
		base = new CsvListReader(core, pref);

		//Get to the first full record in the segment
		if (segStart == 0) {
			for (long i=skip; i>0; i--) {base.read();}					
		} else {
			base.read();
		}
	} catch (IOException e) {
		throw new RuntimeException("Error initializing iterator for " + source.getName(), e);
	}
}
 
開發者ID:JosephCottam,項目名稱:AbstractRendering,代碼行數:19,代碼來源:DelimitedFile.java

示例13: readCsv

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
public void readCsv(BufferedReader reader, char separator) {
    CsvListReader csvReader = new CsvListReader(reader, createPreference(separator));
    List<String> nextLine;
    try {
        while ((nextLine = csvReader.read()) != null) {
            if (nextLine.size() != 2) {
                throw new PowsyblException("Invalid line '" + nextLine + "'");
            }
            mapping.put(nextLine.get(0), nextLine.get(1));
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:15,代碼來源:StringAnonymizer.java

示例14: getCombinedCsvStatistics

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
static Collection<Statistics[]> getCombinedCsvStatistics(final Collection<File> csv_files, CellProcessor[] processors, Integer[] column_indices, boolean header) throws IOException {

        final List<Statistics[]> point_statistics = new ArrayList<Statistics[]>();
        final List<CsvListReader> readers = getCsvListReaders(csv_files, header);

        while (!readers.isEmpty()) {

            final Iterator<CsvListReader> readers_iterator = readers.iterator();
            final Statistics[] combined_statistics = new Statistics[column_indices.length];
            while (readers_iterator.hasNext()) {
                final CsvListReader reader = readers_iterator.next();
                final List<Object> row = reader.read(processors);
                if (row != null) {

                    int i = 0;
                    for (Integer index : column_indices) {
                        if (combined_statistics[i] == null) {
                            combined_statistics[i] = new Statistics();
                        }
                        combined_statistics[i].addSample((Number) row.get(index));
                        i++;
                    }
                }
                else {
                    reader.close();
                    readers_iterator.remove();
                }
            }
            if (combined_statistics[0] != null) {
                point_statistics.add(combined_statistics);
            }
        }

        return point_statistics;
    }
 
開發者ID:stacs-srg,項目名稱:shabdiz,代碼行數:36,代碼來源:AnalyticsUtil.java

示例15: testNewLineInDelimitedField

import org.supercsv.io.CsvListReader; //導入方法依賴的package包/類
@Test
public void testNewLineInDelimitedField() throws IOException {
	String csv = "\"Jo\nhn\",\"Con\nnor\"\n";
	CellProcessor[] processors = { new NotNull(), new NotNull() };
	
	CsvPreference customPreference = new Builder('"', ',', "\n").build();
	CsvListReader listReader = new CsvListReader(new StringReader(csv), customPreference);
	List<Object> result = listReader.read(processors);
	
	Assert.assertNotNull(result);
	Assert.assertEquals(2, result.size());
	Assert.assertEquals("Jo\nhn", result.get(0));
	Assert.assertEquals("Con\nnor", result.get(1));
}
 
開發者ID:super-csv,項目名稱:super-csv,代碼行數:15,代碼來源:ReadingFeaturesTest.java


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