コード例 #1
0
ファイル: CsvParser.java プロジェクト: jwatral/BiggerBiceps
  public static List<ExerciseSet> importFromCsvFile(File f)
      throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
    Reader reader = new FileReader("persons.csv");
    List<ExerciseSet> result = new ArrayList<ExerciseSet>();

    ValueProcessorProvider provider = new ValueProcessorProvider();
    CSVEntryParser<CsvBean> entryParser =
        new AnnotationEntryParser<CsvBean>(CsvBean.class, provider);
    CSVStrategy strategy = new CSVStrategy(';', '"', '#', true, true);
    CSVReader<CsvBean> csvPersonReader =
        new CSVReaderBuilder<CsvBean>(reader).strategy(strategy).entryParser(entryParser).build();

    Iterator<CsvBean> it = csvPersonReader.iterator();
    CsvBean previousBean = new CsvBean();
    //        JMapper mapper = new JMapper(CsvBean.class, ExerciseSet.class);
    while (it.hasNext()) {
      CsvBean bean = it.next();
      merge(previousBean, bean);

      //            result.add((ExerciseSet) mapper.getDestination(previousBean));

      // ...
    }

    return result;
  }
コード例 #2
0
ファイル: CSVFormLoader.java プロジェクト: fjsnogueira/WIngo
  private void fetchData() throws IOException {
    final BufferedReader reader = new BufferedReader(new FileReader(file));
    final CSVReader<Form> csvReader = new CSVReaderBuilder<Form>(reader).build();
    final List<Form> list = csvReader.readAll();

    list.parallelStream().forEach(form -> school.addForm(form));

    reader.close();
  }
コード例 #3
0
 @Override
 public Header parseEntry(String... data) {
   Reader csvFile = CSVHelper.getInputStream();
   CSVReader<Header> headerCSVReader =
       new CSVReaderBuilder<Header>(csvFile)
           .strategy(new CSVStrategy(',', '"', '#', false, true))
           .entryParser(new HeaderController())
           .build();
   List<String> strings = null;
   try {
     strings = headerCSVReader.readHeader();
   } catch (IOException e) {
     e.printStackTrace();
   }
   strings.add(0, "No.");
   return new Header(
       Arrays.asList(strings.get(0), strings.get(1), strings.get(5), strings.get(2)));
 }
コード例 #4
0
ファイル: Bank.java プロジェクト: samdwise/pension
  public static void saveUpload(Reader csvFile, CSVStrategy strategy, ValueProcessorProvider vpp) {
    try {

      CSVReaderBuilder<Bank> builder = new CSVReaderBuilder<Bank>(csvFile);

      builder.strategy(strategy);
      CSVReader<Bank> csvReader =
          builder.entryParser(new AnnotationEntryParser<Bank>(Bank.class, vpp)).build();

      List<Bank> banks = csvReader.readAll();
      for (Bank bank : banks) {
        XPersistence.getManager().merge(bank);
      }

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }