Package au.com.bytecode.opencsv

Examples of au.com.bytecode.opencsv.CSVReader


      , String file, String charset)
  {
    File emailsFile = new File(file);
    logger.info("Get person parameters from file: " + emailsFile.getAbsolutePath());
    String[] headers = null;
    CSVReader reader = null;
    try
    {
      FileInputStream fis = new FileInputStream(emailsFile);
      InputStreamReader isr = new InputStreamReader(fis, charset);
      reader=new CSVReader(isr, ',','"',false);
      headers = reader.readNext();
      personParameters.addAll(reader.readAll());
      reader.close();
    }catch (FileNotFoundException fnfe)
    {
      System.err.println("File with emails not exists: " + file);
      logger.error("File with emails not exists: " + emailsFile.getAbsolutePath());
      System.exit(1);
View Full Code Here


            throw new AssertionError(ex);
        }

        String responseBody = doHttp(historicalPricesUrl, "GET", null);

        CSVReader reader = new CSVReader(new StringReader(responseBody));

        ArrayList<HistoricalPrice> result = new ArrayList<HistoricalPrice>();
        String[] nextLine;

        try {
            while ((nextLine = reader.readNext()) != null) {
                HistoricalPrice hp = new HistoricalPrice();
                hp.setTime(DateTime.parse(nextLine[0]));
                hp.setSpotPrice(Money.of(CurrencyUnit.USD, new BigDecimal(nextLine[1])));
                result.add(hp);
            }
        } catch (IOException e) {
            throw new CoinbaseException("Error parsing csv response");
        } finally {
            try {
                reader.close();
            } catch (IOException e) {}
        }

        return result;
    }
View Full Code Here

    {
      throw new IllegalStateException("The PlayTrade order file '"+m_file.getCanonicalPath()+"' does not exist");
    }
 
    Date youngest_order_date_found = null;
    CSVReader csvparser = new CSVReader(getFileAsInputStream(PLAYTRADE_FILE_ENCODING,getDiscardBOM()), FLAT_FILE_DELIMITER, '~')//need to use a quote char that isnt in the file because csvreader seems to use " be default if one isnt specified, (if file has no delimiter)
   
    String[] headerline = csvparser.readNext();

    String[] line = null//the current line being read from the csv file      
    while( (line = csvparser.readNext()) != null )
    {         
      if ( line.length != headerline.length )
      {
        csvparser.close();
        throw new Error("The row doesn't have the same number of columns as the header " + line.length + "!=" + headerline.length);
      }
     
      OrderReportRow order_record = new OrderReportRow();
     
      order_record.setPaymentsStatus( line[ OrderReport.Header.PAYMENTS_STATUS.getIndex(headerline) ] );
      order_record.setOrderId( line[ OrderReport.Header.ORDER_ID.getIndex(headerline) ] );
      order_record.setItemName( line[ OrderReport.Header.ITEM_NAME.getIndex(headerline) ] );
      order_record.setListingId( line[ OrderReport.Header.LISTING_ID.getIndex(headerline) ] );
      order_record.setSku( line[ OrderReport.Header.SKU.getIndex(headerline) ] );
      order_record.setDeliveredPriceGbp( line[ OrderReport.Header.DELIVERED_PRICE_GBP.getIndex(headerline) ] );
      order_record.setDeliveredPriceEuro( line[ OrderReport.Header.DELIVERED_PRICE_EURO.getIndex(headerline) ] );
      order_record.setPurchaseDate( line[ OrderReport.Header.PURCHASE_DATE.getIndex(headerline) ] );
      order_record.setBuyerEmail( line[ OrderReport.Header.BUYER_EMAIL.getIndex(headerline) ] );
      order_record.setBuyerName( line[ OrderReport.Header.BUYER_NAME.getIndex(headerline) ] );
      order_record.setRecipientName( line[ OrderReport.Header.RECIPIENT_NAME.getIndex(headerline) ] );
      order_record.setShipAddress1( line[ OrderReport.Header.SHIP_ADDRESS_1.getIndex(headerline) ] );
      order_record.setShipAddress2( line[ OrderReport.Header.SHIP_ADDRESS_2.getIndex(headerline) ] );
      order_record.setShipCity( line[ OrderReport.Header.SHIP_CITY.getIndex(headerline) ] );
      order_record.setShipPostcode( line[ OrderReport.Header.SHIP_POSTCODE.getIndex(headerline) ] );
      order_record.setShipCountry( line[ OrderReport.Header.SHIP_COUNTRY.getIndex(headerline) ] );
      order_record.setExchangeRate( line[ OrderReport.Header.EXCHANGE_RATE.getIndex(headerline) ] );
      order_record.setSaleValueGbp( line[ OrderReport.Header.SALE_VALUE_GBP.getIndex(headerline) ] );
      order_record.setSaleValueEuro( line[ OrderReport.Header.SALE_VALUE_EURO.getIndex(headerline) ] );
      order_record.setPlaytradeFeesGbp( line[ OrderReport.Header.PLAYTRADE_FEES_GBP.getIndex(headerline) ] );
      order_record.setPlaytradeFeesEuro( line[ OrderReport.Header.PLAYTRADE_FEES_EURO.getIndex(headerline) ] );
      order_record.setProceedsGbp( line[ OrderReport.Header.PROCEEDS_GBP.getIndex(headerline) ] );
      order_record.setProceedsEuro( line[ OrderReport.Header.PROCEEDS_EURO.getIndex(headerline) ] );
      order_record.setDispatched( line[ OrderReport.Header.DISPATCHED.getIndex(headerline) ] );
                              
      //send this to the listener
      listener.found(order_record);     
     
      //save the date/time of the youngest order
      Date purchasedate = PlayTradeUtils.parsePlayTradeDateTime(order_record.getPurchaseDate());
      if ( youngest_order_date_found == null || youngest_order_date_found.before(purchasedate) )
      {
        youngest_order_date_found = purchasedate;
      }
    }
   
    csvparser.close();
     
    return youngest_order_date_found;
  }
View Full Code Here

    else if ( m_file.exists() == false )
    {
      throw new IllegalStateException("The PlayTrade Competitor Pricing Report file '"+m_file.getCanonicalPath()+"' does not exist");
    }
 
    CSVReader csvparser = new CSVReader(getFileAsInputStream(PLAYTRADE_FILE_ENCODING,getDiscardBOM()), FLAT_FILE_DELIMITER, '~')//need to use a quote char that isnt in the file because csvreader seems to use " be default if one isnt specified, (if file has no delimiter)
   
    String[] headerline = csvparser.readNext();

    String[] line = null//the current line being read from the csv file      
    while( (line = csvparser.readNext()) != null )
    {         
      if ( line.length != headerline.length )
      {
        csvparser.close();
        throw new Error("The row doesn't have the same number of columns as the header " + line.length + "!=" + headerline.length);
      }
     
      AdvancedPricingReportRow aprr = new AdvancedPricingReportRow();
     
      aprr.setListingId( line[ AdvancedPricingReport.Header.LISTING_ID.getIndex(headerline) ] );
      aprr.setSku( line[ AdvancedPricingReport.Header.SKU.getIndex(headerline) ] );
      aprr.setItemName( line[ AdvancedPricingReport.Header.ITEM_NAME.getIndex(headerline) ] );
      aprr.setQuantity( line[ AdvancedPricingReport.Header.QUANTITY.getIndex(headerline) ] );     
      aprr.setDeliveredPriceGBP( line[ AdvancedPricingReport.Header.DELIVERED_PRICE_GBP.getIndex(headerline) ] );
      aprr.setDeliveredPriceEuro( line[ AdvancedPricingReport.Header.DELIVERED_PRICE_EURO.getIndex(headerline) ] );
      aprr.setPlayPriceGBP( line[ AdvancedPricingReport.Header.PLAY_PRICE_GBP.getIndex(headerline) ] );
      aprr.setPlayPriceEuro( line[ AdvancedPricingReport.Header.PLAY_PRICE_EURO.getIndex(headerline) ] );
      aprr.setPlayAvailability( line[ AdvancedPricingReport.Header.PLAY_AVAILABILITY.getIndex(headerline) ] );
      aprr.setCheapestOtherGBP( line[ AdvancedPricingReport.Header.CHEAPEST_OTHER_GBP.getIndex(headerline) ] );
      aprr.setCheapestOtherGBPCondition( line[ AdvancedPricingReport.Header.CHEAPEST_OTHER_GBP_CONDITION.getIndex(headerline) ] );
      aprr.setCheapestotherEuro( line[ AdvancedPricingReport.Header.CHEAPEST_OTHER_EURO.getIndex(headerline) ] );
      aprr.setCheapestOtherEuroCondition( line[ AdvancedPricingReport.Header.CHEAPEST_OTHER_EURO_CONDITION.getIndex(headerline) ] );
     
                                          
      //send this to the listener
      listener.found(aprr);
    }
     
    csvparser.close();
   
    return null;
  }
View Full Code Here

    else if ( m_file.exists() == false )
    {
      throw new IllegalStateException("The PlayTrade Pricing Report file '"+m_file.getCanonicalPath()+"' does not exist");
    }
 
    CSVReader csvparser = new CSVReader(getFileAsInputStream(PLAYTRADE_FILE_ENCODING,getDiscardBOM()), FLAT_FILE_DELIMITER, '~')//need to use a quote char that isnt in the file because csvreader seems to use " be default if one isnt specified, (if file has no delimiter)
   
    String[] headerline = csvparser.readNext();

    String[] line = null//the current line being read from the csv file      
    while( (line = csvparser.readNext()) != null )
    {         
      if ( line.length != headerline.length )
      {
        csvparser.close();
        throw new Error("The row doesn't have the same number of columns as the header " + line.length + "!=" + headerline.length);
      }
     
      PricingReportRow cprr = new PricingReportRow();
     
      cprr.setItemName( line[ PricingReport.Header.ITEM_NAME.getIndex(headerline) ] );
      cprr.setProductId( line[ PricingReport.Header.PRODUCT_ID.getIndex(headerline) ] );
      cprr.setProductIdType( line[ PricingReport.Header.PRODUCT_ID_TYPE.getIndex(headerline) ] );
      cprr.setSku( line[ PricingReport.Header.SKU.getIndex(headerline) ] );
      cprr.setListingId( line[ PricingReport.Header.LISTING_ID.getIndex(headerline) ] );
      cprr.setOpenDate( line[ PricingReport.Header.OPEN_DATE.getIndex(headerline) ] );
      cprr.setDispatchTo( line[ PricingReport.Header.OPEN_DATE.getIndex(headerline) ] );
      cprr.setDeliveredPriceGBP( line[ PricingReport.Header.DELIVERED_PRICE_GBP.getIndex(headerline) ] );
      cprr.setDeliveredPriceEuro( line[ PricingReport.Header.DELIVERED_PRICE_EURO.getIndex(headerline) ] );
      cprr.setCheapestDeliveredPriceGBP( line[ PricingReport.Header.CHEAPEST_DELIVERED_PRICE_GBP.getIndex(headerline) ] );
      cprr.setCheapestDeliveredPriceEuro( line[ PricingReport.Header.CHEAPEST_DELIVERED_PRICE_EURO.getIndex(headerline) ] );
      cprr.setQuantity( line[ PricingReport.Header.QUANTITY.getIndex(headerline) ] );
      cprr.setComment( line[ PricingReport.Header.COMMENT.getIndex(headerline) ] );
      cprr.setItemCondition( line[ PricingReport.Header.ITEM_CONDITION.getIndex(headerline) ] );
      cprr.setDispatchFrom( line[ PricingReport.Header.DISPATCH_FROM.getIndex(headerline) ] );
                                          
      //send this to the listener
      listener.found(cprr);
    }
     
    csvparser.close();
   
    return null;
  }
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

    private static List<String[]> DATA;

    @BeforeClass
    public static void init() throws ClassNotFoundException, SQLException, IOException {
        truncate("orders");
        CSVReader reader = new CSVReader(
                new InputStreamReader(ClassLoader.getSystemResourceAsStream("order.csv")));
        DATA = reader.readAll();
        DATA.remove(0);     //remove header
    }
View Full Code Here

    private static List<OrderVO> DATA;

    @BeforeClass
    public static void init() throws ClassNotFoundException, SQLException, IOException, ParseException {
        truncate("orders");
        CSVReader reader = new CSVReader(
                new InputStreamReader(ClassLoader.getSystemResourceAsStream("order.csv")));
        List<String[]> data = reader.readAll();
        data.remove(0);     //remove header
        DATA = new ArrayList<OrderVO>();
        for (String[] s : data) {
            DATA.add(new OrderVO(Long.valueOf(s[0]), Long.valueOf(s[1]), s[2], Integer.valueOf(s[3]),
                    Integer.valueOf(s[4]), DATA_FORMAT.parse(s[5])));
View Full Code Here

   * @param fileName
   * @throws Exception
   */
  public void upsert(String fileName) throws Exception {
        List<String> delimiter = this.delimiter;
        CSVReader reader;
        if ((delimiter != null) && (delimiter.size() == 3)) {
            reader = new CSVReader(new FileReader(fileName),
                getCSVCustomField(this.delimiter.get(0)),
                getCSVCustomField(this.delimiter.get(1)),
                getCSVCustomField(this.delimiter.get(2)));
        } else {
            reader = new CSVReader(new FileReader(fileName));
        }
        upsert(reader);
  }
View Full Code Here

    */
   
    @Override
    public void map(LongWritable key, Text line, Context context) throws IOException, InterruptedException{
     
      CSVReader reader = new CSVReader(new InputStreamReader(new ByteArrayInputStream(line.toString().getBytes())), ',');     
      try {
        String[] tokens = reader.readNext();
       
        PreparedStatement upsertStatement;
        if(tokens.length >= stmtCache.length){
          //If CVS values are more than the number of cols in the table, apply the col count cap
          upsertStatement = stmtCache[stmtCache.length - 1];
        }else{
          //Else, take the corresponding upsertStmt from cached array
          upsertStatement = stmtCache[tokens.length - 1];
        }

        for(int i = 0 ; i < tokens.length && i < colDetails.size() ;i++){
          upsertStatement.setObject(i+1, convertTypeSpecificValue(tokens[i], colDetails.get(new Integer(i+1))));
        }
       
        upsertStatement.execute();
      } catch (SQLException e) {
        System.err.println("Failed to upsert data in the Phoenix :: " + e.getMessage());
        if(!ignoreUpsertError){
          throw (new InterruptedException(e.getMessage()));
        }
      } catch (Exception e) {
        System.err.println("Failed to upsert data in the Phoenix :: " + e.getMessage());
      }finally {
        reader.close();
             }
     
      Iterator<Pair<byte[],List<KeyValue>>> dataIterator = null;
      try {
        dataIterator = PhoenixRuntime.getUncommittedDataIterator(conn_zk);
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.