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