Package com.csvreader

Examples of com.csvreader.CsvWriter


  @Test
  public void test57() throws Exception {
    byte[] buffer;

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    CsvWriter writer = new CsvWriter(stream, '\t', Charset
        .forName("ISO-8859-1"));
    Assert.assertTrue(writer.getUseTextQualifier());
    writer.setUseTextQualifier(false);
    Assert.assertFalse(writer.getUseTextQualifier());
    writer.write("1,2");
    writer.write("3");
    writer.write("blah \"some stuff in quotes\"");
    writer.endRecord();
    writer.close();

    buffer = stream.toByteArray();
    stream.close();

    String data = Charset.forName("ISO-8859-1").decode(
View Full Code Here


            path = runtimeProperties.getProperty(String.format("csvTarget.%1$s.path", name));
        }
       
        try {
            // Initialize writer
            writer = new CsvWriter(new BufferedWriter(new FileWriter(path)), delimiter);
           
            if (columns == null) {
                Logger.getLogger(CsvTarget.class).info(
                        "Output columns unspecified, using detection from first record.");
            } else {
View Full Code Here

            for (int i = 0; i < columnsToExport.length; i++) {
                columnsToExport[i] = columns[i].getIndex();
            }
        }

        CsvWriter writer = new CsvWriter(out, separator, charset);



        //Write column headers:
        for (int column = 0; column < columnsToExport.length; column++) {
            int columnIndex = columnsToExport[column];

            if (columnIndex == FAKE_COLUMN_EDGE_SOURCE) {
                writer.write("Source");
            } else if (columnIndex == FAKE_COLUMN_EDGE_TARGET) {
                writer.write("Target");
            } else if (columnIndex == FAKE_COLUMN_EDGE_TYPE) {
                writer.write("Type");
            } else {
                writer.write(table.getColumn(columnIndex).getTitle(), true);
            }

        }
        writer.endRecord();

        //Write rows:
        Object value;
        String text;
        for (int row = 0; row < rows.length; row++) {
            for (int column = 0; column < columnsToExport.length; column++) {
                int columnIndex = columnsToExport[column];
               
                if (columnIndex == FAKE_COLUMN_EDGE_SOURCE) {
                    value = ((Edge)rows[row]).getSource().getNodeData().getId();
                } else if (columnIndex == FAKE_COLUMN_EDGE_TARGET) {
                    value = ((Edge)rows[row]).getTarget().getNodeData().getId();
                } else if (columnIndex == FAKE_COLUMN_EDGE_TYPE) {
                    value = ((Edge)rows[row]).isDirected() ? "Directed" : "Undirected";
                } else {
                    value = rows[row].getAttributes().getValue(columnIndex);
                }

                if (value != null) {
                    text = value.toString();
                } else {
                    text = "";
                }
                writer.write(text, true);
            }
            writer.endRecord();
        }
        writer.close();
    }
View Full Code Here

   
    List<String> cells = GeocellManager.bestBboxSearchCells(bb, null);
   
    resp.setContentType("text/csv");
    resp.setHeader("Content-Disposition", "attachment; filename=poi.csv");
    CsvWriter writer = new CsvWriter(resp.getWriter(), ',');
   
    int count = 0;
   
    for (Place place: ofy().load().type(Place.class).filter("cells in", cells)) {
      // The geocell query is not exact, so let's exclude items that don't match the bounding box
      if (!place.isIn(bb))
        continue;
     
      writer.write("" + place.getCenter().getLatitude());
      writer.write("" + place.getCenter().getLongitude());
      String name = (place.getName() == null || place.getName().trim().length() == 0) ? "Unknown" : place.getName();
      writer.write(name);
      writer.endRecord();
      count++;
    }
   
    if (log.isDebugEnabled())
      log.debug("Downloaded " + count + " records");
View Full Code Here

    }
       
    protected void writeCsv(String outFileName, ResultSet results) {
        LOG.debug("Writing population to CSV: {}", outFileName);
        try {
            CsvWriter writer = new CsvWriter(outFileName, ',', Charset.forName("UTF8"));
            writer.writeRecord( new String[] {"label", "lat", "lon", "input", "output"} );
            int i = 0;
            int j = 0;
            // using internal list rather than filtered iterator
            for (Individual indiv : this.individuals) {
                if ( ! this.skip[i]) {
                    String[] entries = new String[] {
                            indiv.label, Double.toString(indiv.lat), Double.toString(indiv.lon),
                            Double.toString(indiv.input), Double.toString(results.results[j])
                    };
                    writer.writeRecord(entries);
                    j++;
                }
                i++;
            }
            writer.close(); // flush writes and close
        } catch (Exception e) {
            LOG.error("Error while writing to CSV file: {}", e.getMessage());
            return;
        }
        LOG.debug("Done writing population to CSV at {}.", outFileName);
View Full Code Here

        }

        /* open output stream (same for all commands) */
        if (outPath != null) {
            try {
                writer = new CsvWriter(outPath, ',', Charset.forName("UTF8"));
            } catch (Exception e) {
                LOG.error("Exception while opening output file " + outPath);
                return;
            }
        } else {
            writer = new CsvWriter(System.out, ',', Charset.forName("UTF8"));
        }
        LOG.info("done loading graph.");
       
        String command = jc.getParsedCommand();
        if (command.equals("endpoints")) {
View Full Code Here

        this.state = state;
        String typeName = query.getTypeName();
        File file = ((CSVDataStore) state.getEntry().getDataStore()).file;
        File directory = file.getParentFile();
        this.temp = File.createTempFile(typeName + System.currentTimeMillis(), "csv", directory);
        this.csvWriter = new CsvWriter(new FileWriter(this.temp), ',');
        this.delegate = new CSVFeatureReader(state,query);
        this.csvWriter.writeRecord(delegate.reader.getHeaders());
    }
View Full Code Here

            if (descriptor instanceof GeometryDescriptor)
                continue;
            header.add(descriptor.getLocalName());
        }
        // Write out header, producing an empty file of the correct type
        CsvWriter writer = new CsvWriter(new FileWriter(file),',');
        try {
            writer.writeRecord( header.toArray(new String[header.size()]));
        }
        finally {
            writer.close();
        }
    }
View Full Code Here

            for (int i = 0; i < columnsToExport.length; i++) {
                columnsToExport[i] = i;
            }
        }

        CsvWriter writer = new CsvWriter(out, separator, charset);

        //Write column headers:
        for (int column = 0; column < columnsToExport.length; column++) {
            writer.write(model.getColumnName(columnsToExport[column]), true);
        }
        writer.endRecord();

        //Write rows:
        Object value;
        String text;
        for (int row = 0; row < table.getRowCount(); row++) {
            for (int column = 0; column < columnsToExport.length; column++) {
                value = model.getValueAt(table.convertRowIndexToModel(row), columnsToExport[column]);
                if (value != null) {
                    text = value.toString();
                } else {
                    text = "";
                }
                writer.write(text, true);
            }
            writer.endRecord();
        }
        writer.close();
    }
View Full Code Here

                    }

                }
            }
 
            CsvWriter csvWriter = new CsvWriter(resource.getOutputStream(), COMMA_SEPARATOR,Charset.defaultCharset());
            // finally we have the values in order to be written to the CSV file.
            for (String[] data : writableData) {
                csvWriter.writeRecord(data);
               
            }
            csvWriter.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }catch(Exception ex){
          ex.printStackTrace();
View Full Code Here

TOP

Related Classes of com.csvreader.CsvWriter

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.