Package au.com.bytecode.opencsv

Examples of au.com.bytecode.opencsv.CSVReader


    }

    @Override
    public long doConversion(DailyMileClient client) {
        long migrated = 0;
        CSVReader reader = null;
       
        try {
            reader = new CSVReader(new FileReader(getInputFilePath()));
            String [] nextLine = reader.readNext();
          
            //skip the first line, it is a header row
            if (nextLine == null) {
                return 0;
            }
           
            while ((nextLine = reader.readNext()) != null) {
                // nextLine[] is an array of values from the line
                Workout wo = createWorkout(nextLine);
                client.addWorkout(wo, nextLine[RunKeeperField.NOTE.getFieldIndex()]);
                migrated++;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (Exception e) {
                    // ignore
                }
            }
        }
View Full Code Here


        String inputFilePath =
            this.getClass().getResource("/com/pc/dailymile/cli/runkeeper/runkeeper.csv")
                    .getFile();
        RunKeeperConverter rkc = new RunKeeperConverter(inputFilePath);

        CSVReader reader = null;
        try {
           
            reader = new CSVReader(new FileReader(inputFilePath));
            List<String[]> lines = reader.readAll();

               
            //first row is headers, so start at 1
            String[] nextLine = lines.get(1);
           
            Workout wo = rkc.createWorkout(nextLine);
            assertEquals(Type.Running, wo.getType());
            assertEquals(1740L, wo.getDuration().longValue());
            assertEquals(Units.kilometers, wo.getDistanceUnits());
            assertEquals("1.17", wo.getDistanceValue());
           
            nextLine = lines.get(2);
            wo = rkc.createWorkout(nextLine);
            assertEquals(Type.Walking, wo.getType());
            assertEquals(1241L, wo.getDuration().longValue());
            assertEquals(Units.kilometers, wo.getDistanceUnits());
            assertEquals("0.96", wo.getDistanceValue());

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (Exception e) {
                    // ignore
                }
            }
        }
View Full Code Here

        }
        return _columns;
    }

    private Column[] buildColumns() {
        CSVReader reader = null;
        try {
            reader = _schema.getDataContext().createCsvReader(0);

            final int columnNameLineNumber = _schema.getDataContext().getConfiguration().getColumnNameLineNumber();
            for (int i = 1; i < columnNameLineNumber; i++) {
                reader.readNext();
            }
            final String[] columnHeaders = reader.readNext();

            reader.close();
            return buildColumns(columnHeaders);
        } catch (IOException e) {
            throw new IllegalStateException("Exception reading from resource: "
                    + _schema.getDataContext().getResource().getName(), e);
        } finally {
View Full Code Here

        final boolean failOnInconsistentRowLength = _configuration.isFailOnInconsistentRowLength();

        final Integer maxRowsOrNull = (maxRows > 0 ? maxRows : null);

        if (_configuration.isMultilineValues()) {
            final CSVReader csvReader = createCsvReader(reader);
            return new CsvDataSet(csvReader, columns, maxRowsOrNull, columnCount, failOnInconsistentRowLength);
        }

        final CSVParser csvParser = new CSVParser(_configuration.getSeparatorChar(), _configuration.getQuoteChar(),
                _configuration.getEscapeChar());
View Full Code Here

                failOnInconsistentRowLength);
    }

    protected CSVReader createCsvReader(int skipLines) {
        final Reader reader = FileHelper.getReader(_resource.read(), _configuration.getEncoding());
        final CSVReader csvReader = new CSVReader(reader, _configuration.getSeparatorChar(),
                _configuration.getQuoteChar(), _configuration.getEscapeChar(), skipLines);
        return csvReader;
    }
View Full Code Here

                _configuration.getQuoteChar(), _configuration.getEscapeChar(), skipLines);
        return csvReader;
    }

    protected CSVReader createCsvReader(BufferedReader reader) {
        final CSVReader csvReader = new CSVReader(reader, _configuration.getSeparatorChar(),
                _configuration.getQuoteChar(), _configuration.getEscapeChar());
        return csvReader;
    }
View Full Code Here

            .getSystemResourceAsStream(TikaResourceTest.TEST_DOC));

    Reader reader = new InputStreamReader(
        (InputStream) response.getEntity());

    CSVReader csvReader = new CSVReader(reader);

    Map<String, String> metadata = new HashMap<String, String>();

    String[] nextLine;
    while ((nextLine = csvReader.readNext()) != null) {
      metadata.put(nextLine[0], nextLine[1]);
    }

    assertNotNull(metadata.get("Author"));
    assertEquals("Maxim Valyanskiy", metadata.get("Author"));
View Full Code Here

        .post(ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC));
    Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());

    Reader reader = new InputStreamReader((InputStream) response.getEntity());

    @SuppressWarnings("resource")
    CSVReader csvReader = new CSVReader(reader);

    Map<String, String> metadata = new HashMap<String, String>();

    String[] nextLine;
    while ((nextLine = csvReader.readNext()) != null) {
      metadata.put(nextLine[0], nextLine[1]);
    }

    assertNotNull(metadata.get("Author"));
    assertEquals("Maxim Valyanskiy", metadata.get("Author"));
View Full Code Here

            throw new UnsupportedOperationException(
                "A stream from an export endpoint is not supported " +
                "by a CSV result reader. Use XML or JSON search output "+
                "format and matching reader instead."
            );
        csvReader = new CSVReader(new InputStreamReader(inputStream, "UTF-8"));
        // initial line contains the keyArray, except for oneshot -- which
        // contains a blank line, and then the key list.
        String[] keyArray = csvReader.readNext();
        if (keyArray.length == 1 && keyArray[0].trim().equals("")) {
            keyArray = csvReader.readNext();
View Full Code Here

    }
  }

  private static void parseResults(InputStream in, SearchResultListener srl)
      throws IOException {
    CSVReader csvr = new CSVReader(new InputStreamReader(in));
    try {
      String [] header = csvr.readNext();

      if (header != null
          && header.length > 0
          && !(header.length == 1 && header[0].isEmpty())) {
        srl.setFieldNames(header);

        String[] line;
        while ((line = csvr.readNext()) != null) {
          if (line.length == header.length) {
            srl.processSearchResult(line);
          }
        }
      }
View Full Code Here

TOP

Related Classes of au.com.bytecode.opencsv.CSVReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.