Package au.com.bytecode.opencsv

Examples of au.com.bytecode.opencsv.CSVReader


     * </ul>
     */
    private int source;

    public SplunkResultEnumerator(InputStream in, List<String> wantedFields) {
      csvReader = new CSVReader(new InputStreamReader(in));
      try {
        fieldNames = csvReader.readNext();
        if (fieldNames == null
            || fieldNames.length == 0
            || fieldNames.length == 1 && fieldNames[0].isEmpty()) {
View Full Code Here


     * @return CSVReader, must call {@link CSVReader#close()} to free FileReader
     * @throws FileNotFoundException
     */
    public CSVReader reader() throws IOException {
        Reader fileReader = new FileReader( file );
        CSVReader reader = new CSVReader(fileReader);
        String row[] = reader.readNext();
        if( header == null ){
            setHeader(row);
        }
        return reader;
    }
View Full Code Here

    /** Calculate the size of the file */
    public synchronized int getSize(){
        if( size == -1 ){
            size = 0;
            try {
                CSVReader reader = reader();
                String row[] = reader.readNext(); // skip headers!
                while ((row = reader.readNext()) != null) {
                    size++;
                }
            }
            catch (IOException eek){
                eek.printStackTrace();
View Full Code Here

        if (monitor == null)
            monitor = new NullProgressMonitor();

        monitor.beginTask("csv render", 100);

        CSVReader reader = null;
        try {
            g.setColor(Color.BLACK);
            ILayer layer = getContext().getLayer();
            IGeoResource resource = layer.findGeoResource(CSV.class);
            if (resource == null)
                return;

            CoordinateReferenceSystem dataCRS = layer.getCRS();
            CoordinateReferenceSystem worldCRS = context.getCRS();
            MathTransform dataToWorld = CRS.findMathTransform(dataCRS, worldCRS, false);

            ReferencedEnvelope bounds = getRenderBounds();
            monitor.subTask("connecting");
           
            CSV csv = resource.resolve(CSV.class, new SubProgressMonitor(monitor, 10) );
            reader = csv.reader();
           
            int nameIndex = csv.getHeader("name");

            IProgressMonitor drawMonitor = new SubProgressMonitor(monitor, 90);
            Coordinate worldLocation = new Coordinate();
           
            drawMonitor.beginTask("draw "+csv.toString(), csv.getSize());           
            String [] row;
            while ((row = reader.readNext()) != null) {
                Point point = csv.getPoint(row);
                Coordinate dataLocation = point.getCoordinate();
                try {
                    JTS.transform(dataLocation, worldLocation, dataToWorld);
                } catch (TransformException e) {
                    continue;
                }               
                if (bounds != null && !bounds.contains(worldLocation)) {
                    continue; // optimize!
                }               
                java.awt.Point p = getContext().worldToPixel(worldLocation);
                g.fillOval(p.x, p.y, 10, 10);
                String name = row[nameIndex];
                g.drawString(name, p.x + 15, p.y + 15);
                drawMonitor.worked(1);

                if (drawMonitor.isCanceled())
                    break;
            }
            drawMonitor.done();           
        } catch (IOException e) {
            throw new RenderException(e); // rethrow any exceptions encountered
        } catch (FactoryException e) {
            throw new RenderException(e); // rethrow any exceptions encountered
        } finally {
            if (reader != null)
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RenderException(e);
                }
            monitor.done();
        }
View Full Code Here

    public void render_example( Graphics2D g, IProgressMonitor monitor ) throws RenderException {
        if (monitor == null)
            monitor = new NullProgressMonitor();

        monitor.beginTask("csv render", IProgressMonitor.UNKNOWN);
        CSVReader reader = null;
        try {
            g.setColor(Color.BLUE);

            ILayer layer = getContext().getLayer();
            IGeoResource resource = layer.findGeoResource(CSV.class);
            if (resource == null)
                return;

            ReferencedEnvelope bounds = getRenderBounds();
            monitor.subTask("connecting");

            CSV csv = resource.resolve(CSV.class, new SubProgressMonitor(monitor, 10));
            reader = csv.reader();
           
            monitor.subTask("drawing");
            int nameIndex = csv.getHeader("name");
            Coordinate worldLocation = new Coordinate();
            String [] row;
            while ((row = reader.readNext()) != null) {
                Point point = csv.getPoint(row);
                worldLocation = point.getCoordinate();
                if (bounds != null && !bounds.contains(worldLocation)) {
                    continue; // optimize!
                }
                java.awt.Point p = getContext().worldToPixel(worldLocation);
                g.fillOval(p.x, p.y, 10, 10);
                String name = row[nameIndex];
                g.drawString(name, p.x + 15, p.y + 15);
                monitor.worked(1);

                if (monitor.isCanceled())
                    break;
            }
        } catch (IOException e) {
            throw new RenderException(e); // rethrow any exceptions encountered
        } finally {
            if (reader != null)
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RenderException(e); // rethrow any exceptions encountered
                }
            monitor.done();
        }
View Full Code Here

    CSVGeoResource handle;
    public CSVGeoResourceInfo( CSVGeoResource resource, IProgressMonitor monitor ) throws IOException {
        this.handle = resource;
        this.title = handle.getIdentifier().toString();
        CSV csv = handle.getCSV( monitor );
        CSVReader reader = csv.reader();
        try {
            this.description = "Information:";
            for( String header : csv.getHeader() ){
                this.description += " "+header;
            }
            this.bounds = new ReferencedEnvelope(DefaultGeographicCRS.WGS84);
           
            String row[];
            while ((row = reader.readNext()) != null) {
                Point point = csv.getPoint( row );
                if( point == null ) {
                    continue; // what is the point
                }
                this.bounds.expandToInclude(point.getCoordinate());
            }
        }
        finally {
            reader.close();
        }
    }
View Full Code Here

           
           if( resource.canResolve(CSV.class)){
               csv = resource.resolve(CSV.class, null );
           }
        }
        CSVReader reader = csv.reader();
        String row[];
        int count=0;
        int lon = csv.getHeader("x");
        int lat = csv.getHeader("y");
        while ((row = reader.readNext()) != null) {
            String x = row[lon];
            String y = row[lat];
            System.out.print( "row "+count+": point "+x+" x "+y);
            Point point = csv.getPoint( row );
            System.out.println( "-->"+ point );
           
            count++;
        }
        reader.close();
        System.out.println( count );
    }
View Full Code Here

     */
public void render( Graphics2D g, IProgressMonitor monitor ) throws RenderException {
    if (monitor == null)
        monitor = new NullProgressMonitor();

    CSVReader reader = null;
    try {
        ILayer layer = getContext().getLayer();
        IGeoResource resource = layer.findGeoResource(CSV.class);
        if (resource == null)
            return;       
        ReferencedEnvelope bounds = getRenderBounds();
        monitor.subTask("connecting");
        CSV csv = resource.resolve(CSV.class, null);
        // LOOK UP STYLE
        IStyleBlackboard style = layer.getStyleBlackboard();
        Color color = (Color) style.get( ColorStyle.ID );

        // DATA TO WORLD
        CoordinateReferenceSystem dataCRS = layer.getCRS();
        CoordinateReferenceSystem worldCRS = context.getCRS();
        MathTransform dataToWorld = CRS.findMathTransform(dataCRS, worldCRS, false);

        // DRAW FILE
        monitor.beginTask("csv render", csv.getSize());
        reader = csv.reader();
       
        int nameIndex = csv.getHeader("name");
        Coordinate worldLocation = new Coordinate();
        String [] row;
        while ((row = reader.readNext()) != null) {
            Point point = csv.getPoint(row);
            Coordinate dataLocation = point.getCoordinate();
            try {
                JTS.transform(dataLocation, worldLocation, dataToWorld);
            } catch (TransformException e) {
                continue;
            }
            if (bounds != null && !bounds.contains(worldLocation)) {
                continue; // optimize!
            }
            java.awt.Point p = getContext().worldToPixel(worldLocation);

            g.setColor( color );
            g.fillRect(p.x-2, p.y-2, 6, 6);
           
            g.setColor(Color.BLACK);
            String name = row[nameIndex];
            g.drawString(name, p.x + 15, p.y + 15);
            monitor.worked(1);
            if (monitor.isCanceled()) break;
        }
    } catch (IOException e) {
        throw new RenderException(e); // rethrow any exceptions encountered
    } catch (FactoryException e) {
        throw new RenderException(e); // rethrow any exceptions encountered
    } finally {
        if (reader != null)
            try {
                reader.close();
            } catch (IOException e) {
                throw new RenderException(e); // rethrow any exceptions encountered
            }
        monitor.done();
    }
View Full Code Here

  }
 
  public static <T> List<T> fromCSV(Reader reader, ValueConverter<T> valueConverter) {
    try {
      List<T> result = Lists.newArrayList();
      CSVReader csvReader = new CSVReader(reader);
      try {
        for (String[] values : csvReader.readAll()) {
          for (String value : values) {
            value = value.trim();
            if (com.jdroid.java.utils.StringUtils.isNotEmpty(value)) {
              result.add(valueConverter.fromString(value));
            }
          }
        }
        return result;
      } finally {
        csvReader.close();
      }
    } catch (IOException exception) {
      throw new UnexpectedException("Error reading the csv", exception);
    }
  }
View Full Code Here

    public CsvToBean() {
    }

    public List<T> parse(MappingStrategy<T> mapper, Reader reader) {
        return parse(mapper, new CSVReader(reader));
    }
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.