本文整理匯總了Java中au.com.bytecode.opencsv.CSVReader.readNext方法的典型用法代碼示例。如果您正苦於以下問題:Java CSVReader.readNext方法的具體用法?Java CSVReader.readNext怎麽用?Java CSVReader.readNext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類au.com.bytecode.opencsv.CSVReader
的用法示例。
在下文中一共展示了CSVReader.readNext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readAllLines
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
/**
* Read all lines. Add positive and negative examples.
*
* @param reader
* @throws IOException
*/
private void readAllLines(CSVReader reader) throws IOException {
String[] values = null;
while ((values = reader.readNext()) != null) {
if (values.length == 3) {
boolean isPositive = Boolean.parseBoolean(values[2]);
Pair<String, String> example = new Pair<String, String>(
values[0], values[1]);
if (isPositive) {
addPositiveExample(example);
} else {
addNegativeExample(example);
}
} else {
System.err.println(String.format("Skipping malformed line: %s",
StringUtils.join(values,",")));
}
}
}
示例2: loadCSV
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
private void loadCSV(File fpIn, Map<Integer,Double> mapForB, Map<Integer,Double> mapForD,
Map<Integer,Double> mapForR ) throws IOException {
assertTrue(fpIn.exists());
CSVReader reader = new CSVReader(new FileReader(fpIn));
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
String order = nextLine[1].trim();
switch (order) {
case PLACEHOLDER_B : mapForB.put(Integer.parseInt(nextLine[0]), Double.parseDouble(nextLine[2]));
break;
case PLACEHOLDER_D : mapForD.put(Integer.parseInt(nextLine[0]), Double.parseDouble(nextLine[2]));
break;
case PLACEHOLDER_R : mapForR.put(Integer.parseInt(nextLine[0]), Double.parseDouble(nextLine[2]));
break;
}
}
assertTrue(mapForB.size() > 0);
assertEquals(mapForB.size(), mapForD.size());
assertEquals(mapForD.size(), mapForR.size());
reader.close();
}
示例3: main
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
CSVReader reader = new CSVReader(new FileReader(ADDRESS_FILE));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
System.out.println("Name: [" + nextLine[0] + "]\nAddress: [" + nextLine[1] + "]\nEmail: [" + nextLine[2] + "]");
}
// Try writing it back out as CSV to the console
CSVReader reader2 = new CSVReader(new FileReader(ADDRESS_FILE));
List allElements = reader2.readAll();
StringWriter sw = new StringWriter();
CSVWriter writer = new CSVWriter(sw);
writer.writeAll(allElements);
System.out.println("\n\nGenerated CSV File:\n\n");
System.out.println(sw.toString());
}
示例4: reset
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
@Override
public void reset() throws IOException {
csvReader = new CSVReader(new FileReader(file));
String[] line;
while (null != (line = csvReader.readNext())) {
if (line.length > 0 && ! Check.isEmpty(line[0])) {
headings = line;
break;
}
}
if (headings == null) {
throw new IOException("File only has blank lines");
}
}
示例5: fromStream
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
/**
* Generate ReportData from an input stream (normally an HTTP steam of report in CSV format),
* which will be closed after reading.
* @param stream the input stream (in CSV format)
* @param clientCustomerId the client customer ID of this report
* @return the generated ReportData
*/
public ReportData fromStream(InputStream stream, Long clientCustomerId) throws IOException {
CSVReader csvReader = new CSVReader(new InputStreamReader(stream, Charset.defaultCharset()));
String[] headerArray = csvReader.readNext();
List<String[]> rowsArray = csvReader.readAll();
csvReader.close();
int rowsCount = rowsArray.size();
List<List<String>> rows = new ArrayList<List<String>>(rowsCount);
for (int i = 0; i < rowsCount; ++i) {
// need to create a new ArrayList object which is extendible.
List<String> row = new ArrayList<String>(Arrays.asList(rowsArray.get(i)));
rows.add(row);
}
int columns = headerArray.length;
List<String> columnNames = new ArrayList<String>(columns);
for (int i = 0; i < columns; i++) {
String fieldName = fieldsMapping.get(headerArray[i]);
Preconditions.checkNotNull(fieldName, "Unknown field name: %s.", fieldName);
columnNames.add(fieldName);
}
return new ReportData(clientCustomerId, reportType, columnNames, rows);
}
示例6: readMetadataFields
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public String[] readMetadataFields(CSVReader reader) throws IOException {
// read first line from the file, with metadata description
String[] metadataFields = reader.readNext();
if(metadataFields==null)
throw new RuntimeException("Empty input file");
// if there is a mapping for parameters, use it
boolean hasFile = false;
for(int i=0; i < metadataFields.length; i++) {
String value = getParameter(metadataFields[i]);
if(value != null)
metadataFields[i]=value;
logger.debug("Metadata field " + i + ": " + metadataFields[i]);
if(Parameters.PARAM_FILE.equals(metadataFields[i]))
hasFile=true;
}
if(!hasFile) {
throw new RuntimeException("The header should contain the 'file' parameter or there should be a mapping for one of headers parameters to 'file'");
}
return metadataFields;
}
示例7: processFormattedFile
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public void processFormattedFile(BufferedReader fr, FileProcessorState state) throws Exception {
CSVReader csvr = new CSVReader(fr);
String[] line = null;
while (((line = csvr.readNext()) != null)) {
state.setRecordCnt(state.getRecordCnt() + 1);
boolean headerPresent = state.isHeaderRowPresent();
if (state.getColumns() != line.length) {
state.appendError("Wrong Number Columns Row:, " + state.getRecordCnt() + "Saw:" + line.length + ", Expecting: " + state.getColumns());
state.setErrorCnt(state.getErrorCnt() + 1);
} else if ((headerPresent && state.getRecordCnt() > 1) || !headerPresent) {
try {
line = trimLine(line);
processRow(line, state);
state.setProcessedCnt(state.getProcessedCnt() + 1);
} catch (Exception e) {
log.debug(e.getMessage(), e);
state.appendError("Row " + state.getRecordCnt() + " " + e.getMessage());
state.setErrorCnt(state.getErrorCnt() + 1);
}
}
}
fr.close();
}
示例8: readStream
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
/**
* Reads the specified input stream, parsing the exchange data.
* @param inputStream the input stream, not null
*/
public void readStream(InputStream inputStream) {
try {
CSVReader reader = new CSVReader(new InputStreamReader(new BufferedInputStream(inputStream)));
String[] line = reader.readNext(); // header
int[] indices = findIndices(line);
line = reader.readNext();
while (line != null) {
readLine(line, indices);
line = reader.readNext();
}
mergeDocuments();
} catch (IOException ex) {
throw new OpenGammaRuntimeException("Unable to read exchange file", ex);
}
}
示例9: read
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public static List<SoundEvent> read(String file, SoundEvent.Type type) throws IOException{
List<SoundEvent> events = new ArrayList<SoundEvent>();
CSVReader reader = new CSVReader(new FileReader(file));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
if(!isString(nextLine)){
SoundEvent e = new SoundEvent(nextLine[0], nextLine[1]);
e.type = type;
events.add(e);
}
}
reader.close();
return events;
}
示例10: execute
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
@Override
public void execute(Tuple input) {
try{
LocationBoundaryFileDto locationBoundaryFileDto = (LocationBoundaryFileDto)input.getValueByField("locationBoundaryFileDto");
CSVReader csvReader = new CSVReader(new FileReader(locationBoundaryFileDto.getFileNameAndPath()));
String headers[] = csvReader.readNext();
//First column will be latitude and second column will be longitude
String line[];
while((line = csvReader.readNext()) != null){
}
}catch(Exception ex){
collector.fail(input);
}
}
示例11: parse
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public List<T> parse(MappingStrategy<T> mapper, CSVReader csv) {
try {
mapper.captureHeader(csv);
String[] line;
List<T> list = new ArrayList<>();
while (null != (line = csv.readNext())) {
T obj = processLine(mapper, line);
list.add(obj); // TODO: (Kyle) null check object
}
return list;
} catch (IOException | IllegalAccessException | InvocationTargetException | InstantiationException | IntrospectionException e) {
//throw new RuntimeException("Error parsing CSV!", e);
JOptionPane.showMessageDialog(null, "An error occured!", "Error", JOptionPane.ERROR_MESSAGE);
}
return null;
}
示例12: parseDatei
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
/**
* Initialer Aufruf, der die Datei parst. Wird von den Implementierungen der
* Interfaces aufgerufen.
*
* @param in
* InputStream für die einzulesende Datei
*/
protected void parseDatei(InputStream in) throws IOException {
// Momentan statisch mit Semikolon als Delimiter
reader = new CSVReader(new InputStreamReader(in, "ISO-8859-1"), ';');
String[] curLine;
aktuelleZeile = beginneBeiZeile;
for (int i = 0; i < beginneBeiZeile; i++) {
curLine = reader.readNext();
}
while (null != (curLine = reader.readNext())) {
if (curLine.length > 1) {
this.parseZeile(curLine);
}
aktuelleZeile++;
}
// Am Schluss:
reader.close();
this.dateiendeErreicht();
}
示例13: loadCorrespondences
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
/**
* Loads correspondences from a file and adds them to this correspondence
* set. Can be called multiple times.
*
* @param correspondenceFile the file to load from
* @param first the dataset that contains the records
* @throws IOException thrown if there is a problem loading the file
*/
public void loadCorrespondences(File correspondenceFile,
FusibleDataSet<RecordType, SchemaElementType> first)
throws IOException {
CSVReader reader = new CSVReader(new FileReader(correspondenceFile));
String[] values = null;
int skipped = 0;
while ((values = reader.readNext()) != null) {
// check if the ids exist in the provided data sets
if (first.getRecord(values[0]) == null) {
skipped++;
continue;
}
// we only have the records from the source data sets, so we group by the id in the target data set
RecordGroup<RecordType, SchemaElementType> grp2 = recordIndex.get(values[1]);
if (grp2 == null) {
// no existing groups, create a new one
RecordGroup<RecordType, SchemaElementType> grp = groupFactory.createRecordGroup();
grp.addRecord(values[0], first);
recordIndex.put(values[1], grp);
groups.add(grp);
} else {
// one existing group, add to this group
grp2.addRecord(values[0], first);
recordIndex.put(values[0], grp2);
}
}
reader.close();
if (skipped>0) {
System.err.println(String.format("Skipped %,d records (not found in provided dataset)", skipped));
}
}
示例14: loadFromCsv
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public static Processable<Correspondence<RecordId, RecordId>> loadFromCsv(File location) throws IOException {
CSVReader r = new CSVReader(new FileReader(location));
Processable<Correspondence<RecordId, RecordId>> correspondences = new ProcessableCollection<>();
String[] values = null;
while((values = r.readNext())!=null) {
if(values.length>=3) {
String id1 = values[0];
String id2 = values[1];
String sim = values[2];
Double similarityScore = 0.0;
try {
similarityScore = Double.parseDouble(sim);
} catch(Exception ex) {
System.err.println(ex.getMessage());
}
Correspondence<RecordId, RecordId> cor = new Correspondence<RecordId, RecordId>(new RecordId(id1), new RecordId(id2), similarityScore, null);
correspondences.add(cor);
} else {
System.err.println(String.format("Invalid format: \"%s\"", StringUtils.join(values, "\",\"")));
}
}
r.close();
return correspondences;
}
示例15: parse
import au.com.bytecode.opencsv.CSVReader; //導入方法依賴的package包/類
public List parse(MappingStrategy mapper, Reader reader) {
try {
CSVReader csv = new CSVReader(reader);
mapper.captureHeader(csv);
String[] line;
List list = new ArrayList();
while(null != (line = csv.readNext())) {
Object obj = processLine(mapper, line);
list.add(obj); // TODO: (Kyle) null check object
}
return list;
} catch (Exception e) {
throw new RuntimeException("Error parsing CSV!", e);
}
}