本文整理汇总了Java中org.apache.commons.csv.CSVParser类的典型用法代码示例。如果您正苦于以下问题:Java CSVParser类的具体用法?Java CSVParser怎么用?Java CSVParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CSVParser类属于org.apache.commons.csv包,在下文中一共展示了CSVParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseHintFile
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
private HashMap<String, Map<String, String>> parseHintFile(Integer exercise, Integer exercise_order) {
final HashMap<String, Map<String, String>> list;
final CSVParser parser;
final URL resource;
final CSVFormat csvFormat;
final Charset charset;
list = new HashMap<String, Map<String, String>> ();
try {
resource = ResourceHelper.getResource(BuenOjoFileUtils.GAME_RESOURCES_INPUT_DIR ,this.gamePath,this.setPath,exercise.toString(),exercise_order.toString(),"xy_pista.csv");
charset= FileEncodingDetectorHelper.guessEncodingAndGetCharset(resource);
csvFormat = CSVFormatHelper.getDefaultCSVFormat();
parser = CSVParser.parse(resource, charset, csvFormat);
for (CSVRecord record : parser )
list.put(record.get("id").trim() , (Map<String, String>)record.toMap());
}
catch (IOException e) {
log.error("Fail",e);
}
return list;
}
示例2: parse
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
private ArrayList<Map<String, String>> parse() {
final ArrayList<Map<String, String>> list;
final CSVParser parser;
final URL resource;
final CSVFormat csvFormat;
final Charset charset;
list = new ArrayList<Map<String, String>> ();
try {
resource = ResourceHelper.getResource(isFromGameResourceInput(),fileName);
charset= FileEncodingDetectorHelper.guessEncodingAndGetCharset(resource);
csvFormat = CSVFormatHelper.getDefaultCSVFormat();
parser = CSVParser.parse(resource, charset, csvFormat);
for (CSVRecord record : parser )
list.add((Map<String, String>)record.toMap());
}
catch (IOException e) {
log.error("Fail", e);
}
return list;
}
示例3: read
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
@Override
public T read() throws MintleafException {
final CSVParser parser;
try {
parser = getCSVParser();
int i = 0;
for (CSVRecord record : parser) {
Row row = createRowInstance(record);
if (!readRow(i++, row)) {
break;
}
}
} catch (IOException e) {
throw new MintleafException(e);
}
return null;
}
示例4: parse
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
private ArrayList<Map<String,String>> parse() {
ArrayList<Map<String,String>> list;
CSVParser parser;
URL resource;
CSVFormat csvFormat;
Charset charset;
list = new ArrayList<Map<String,String>> ();
try {
resource = ResourceHelper.getResource(isFromGameResourceInput(),fileName);
charset= FileEncodingDetectorHelper.guessEncodingAndGetCharset(resource);
csvFormat = CSVFormatHelper.getDefaultCSVFormat();
parser = CSVParser.parse(resource, charset, csvFormat);
for (CSVRecord record : parser )
list.add(record.toMap());
}
catch (IOException e) {
log.error("Fail", e);
}
return list;
}
示例5: parseDelimitedAreaFile
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
private Map<String,String> parseDelimitedAreaFile(Integer exercise, Integer exercise_order) {
Map<String,String> list;
CSVParser parser;
URL resource;
CSVFormat csvFormat;
Charset charset;
list = new HashMap<String,String>();
try {
resource =ResourceHelper.getResource(isFromGameResourceInput(),this.gamePath,this.setPath,exercise.toString(), exercise_order.toString(),"areaDelimitada.csv");
charset= FileEncodingDetectorHelper.guessEncodingAndGetCharset(resource);
csvFormat = CSVFormatHelper.getDefaultCSVFormat();
parser = CSVParser.parse(resource, charset, csvFormat);
for (CSVRecord record : parser )
list = record.toMap();
}
catch (IOException e) {
log.error("Fail",e);
}
return list;
}
示例6: createTags
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
private List <Tag> createTags(CSVParser parser, Course course) {
tagMap = new HashMap<>();
ArrayList<Tag> tagList = new ArrayList<Tag>();
for (CSVRecord csvRecord : parser) {
String name = csvRecord.get(TagPoolColumn.TAG.ordinal()).toString();
if (!tagMap.containsKey(name)){
Tag tag = new Tag();
tag.setName(name);
tag.setCourse(course);
tagMap.put(name, tag);
tag.setNumber(tagMap.size());
tagList.add(tag);
}
}
return tagList;
}
示例7: parse
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
public List<Map<String,String>> parse() throws BuenOjoCSVParserException {
List<Map<String,String>> list = new ArrayList<>();
CSVParser parser = null;
try {
parser = CSVFormat.RFC4180.withHeader()
.withDelimiter(',')
.withAllowMissingColumnNames(true)
.parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
} catch (IOException e) {
throw new BuenOjoCSVParserException(e.getMessage());
}
for (CSVRecord record :parser) {
Map<String,String> map = record.toMap();
list.add(map);
}
return list;
}
示例8: parse
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
public List<PhotoLocationSightPair> parse () throws IOException, BuenOjoCSVParserException {
CSVParser parser = CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
List<CSVRecord> records = parser.getRecords();
if (records.size() == 0 ) {
throw new BuenOjoCSVParserException("El archivos de miras no contiene registros");
}
ArrayList<PhotoLocationSightPair> sightPairs = new ArrayList<>(records.size());
for (CSVRecord record : records) {
PhotoLocationSightPair sight = new PhotoLocationSightPair();
sight.setNumber(new Integer(record.get(PhotoLocationSightPairCSVColumn.id)));
sight.setSatelliteX(new Integer(record.get(PhotoLocationSightPairCSVColumn.satCol)));
sight.setSatelliteY(new Integer(record.get(PhotoLocationSightPairCSVColumn.satRow)));
sight.setSatelliteTolerance(new Integer(record.get(PhotoLocationSightPairCSVColumn.satTolerancia)));
sight.setTerrainX(new Integer(record.get(PhotoLocationSightPairCSVColumn.terCol)));
sight.setTerrainY(new Integer(record.get(PhotoLocationSightPairCSVColumn.terRow)));
sight.setTerrainTolerance(new Integer(record.get(PhotoLocationSightPairCSVColumn.terTolerancia)));
sightPairs.add(sight);
}
return sightPairs;
}
示例9: parse
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
public List<TagPair> parse() throws IOException {
CSVParser parser = CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
ArrayList<TagPair> tagPairs = new ArrayList<>(AVG_ITEMS);
for (CSVRecord record : parser ){
TagPair pair = new TagPair();
Integer tagSlotId = new Integer(record.get("id"));
Integer tagNumber = new Integer(record.get("etiqueta"));
pair.setTagSlotId(tagSlotId);
Optional<Tag> optionalTag = tagList.stream().filter(isEqualToTagNumber(tagNumber)).findFirst();
if (optionalTag.isPresent()){
Tag tag = optionalTag.get();
pair.setTag(tag);
tagPairs.add(pair);
}else {
log.debug("Attempt to get invalid tag with number: "+tagNumber);
}
}
return tagPairs;
}
示例10: parse
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
public PhotoLocationBeacon parse() throws IOException, BuenOjoCSVParserException {
CSVParser parser = CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
List<CSVRecord> records = parser.getRecords();
if (records.size() > 1) {
throw new BuenOjoCSVParserException("El archivo contiene más de un indicador");
}
if (records.size() == 0) {
throw new BuenOjoCSVParserException("El archivo de indicador es inválido");
}
CSVRecord record = records.get(0);
PhotoLocationBeacon beacon = new PhotoLocationBeacon();
beacon.setX(new Integer(record.get(PhotoLocationBeaconCSVColumns.col.ordinal())));
beacon.setY(new Integer(record.get(PhotoLocationBeaconCSVColumns.row.ordinal())));
beacon.setTolerance(new Integer(record.get(PhotoLocationBeaconCSVColumns.tolerance.ordinal())));
return beacon;
}
示例11: parse
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
public List<TagCircle> parse() throws IOException, BuenOjoCSVParserException {
ArrayList<TagCircle> list = new ArrayList<>(MAX_CIRCLES);
CSVParser parser = CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(false).parse(new InputStreamReader(this.inputStream));
for (CSVRecord record : parser ){
TagCircle circle = new TagCircle();
circle.setNumber(new Integer(record.get("id")));
circle.setX(new Integer(record.get("col")));
circle.setY(new Integer(record.get("row")));
circle.setRadioPx(new Float(record.get("radioPx")));
list.add(circle);
}
if (list.size()>MAX_CIRCLES){
throw new BuenOjoCSVParserException("el archivo contiene mas de "+MAX_CIRCLES+ "áreas circulares");
}
return list;
}
示例12: DataSet
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
/**
* Creates a new dataset with column labels and data read from the given Reader, using a specified input format.
*
* @param reader the Reader to read column labels and data from
* @param input_format the format
*/
@SuppressWarnings("WeakerAccess")
public DataSet(final Reader reader, final CSVFormat input_format) {
this();
try (CSVParser parser = new CSVParser(reader, input_format.withHeader())) {
labels.addAll(getColumnLabels(parser));
for (final CSVRecord record : parser) {
final List<String> items = csvRecordToList(record);
final int size = items.size();
// Don't add row if the line was empty.
if (size > 1 || (size == 1 && items.get(0).length() > 0)) {
records.add(items);
}
}
reader.close();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
示例13: csvToObject
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
public T csvToObject(InputStream is) throws IOException, IllegalArgumentException, IllegalAccessException, InstantiationException {
WrapperReturner<T> list = new WrapperReturner();
try (InputStreamReader br = new InputStreamReader(is)) {
CSVParser parser = new CSVParser(br, CSVFormat.DEFAULT);
for (int i = 0, j = 0; i < parser.getRecordNumber(); i++) {
j = 0;
for (Field field : classFields) {
setFieldValue(field, list.t, parser.getRecords().get(i).get(j));
list.tl.add(list.t);
j++;
}
}
}
return list.t;
}
示例14: compareCSVFiles
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
private void compareCSVFiles(String actualPath, String expectedPath) {
try (CSVParser parserTranslatedFile = createCsvParser(actualPath, ",")) {
try (CSVParser parserExpectedFile = createCsvParser(expectedPath, ",")) {
Iterator<CSVRecord> translatedIterator = parserTranslatedFile.iterator();
Iterator<CSVRecord> expectedIterator = parserExpectedFile.iterator();
while (translatedIterator.hasNext() && expectedIterator.hasNext()) {
CSVRecord translatedRecord = translatedIterator.next();
CSVRecord expectedRecord = expectedIterator.next();
compareCSVRecords(translatedRecord, expectedRecord);
}
if (translatedIterator.hasNext()) {
fail("Actual file is longer (has more lines) than expected file");
}
if (expectedIterator.hasNext()) {
fail("Expected file is longer (has more lines) than actual file");
}
}
} catch (Exception e) {
fail("Exception while iterating over files");
}
}
示例15: updateDB
import org.apache.commons.csv.CSVParser; //导入依赖的package包/类
/**
* sauvegarde dans la base de données
* @param parser
* @return
*/
public int updateDB(CSVParser parser) {
int res = 0;
DBManager.connect();
for (CSVRecord item : parser) {
String serie = item.get(0).trim();
String mention = item.get(1).trim();
String specialite = item.get(2).trim();
String section = item.get(3).trim();
//enregistrer
if (add(serie, mention, specialite, section)){
res++;
}
}
DBManager.quit();
return res;
}