Package au.com.bytecode.opencsv

Examples of au.com.bytecode.opencsv.CSVWriter


                }

                // form csv properties
                StringWriter sw = new StringWriter();
                try {
                    CSVWriter writer = new CSVWriter(sw);
                    Iterator it = propertyMap.entrySet().iterator();
                    while (it.hasNext()) {
                        Map.Entry<String, String> pairs = (Map.Entry) it.next();
                        writer.writeNext(new String[]{pairs.getKey(), pairs.getValue()});
                    }
                    writer.close();
                } catch (Exception ex) {
                    LogUtil.error(getClass().getName(), ex, "");
                }
                String pluginProps = sw.toString();
                participant.setPluginProperties(pluginProps);
View Full Code Here


            }

            // form csv properties
            StringWriter sw = new StringWriter();
            try {
                CSVWriter writer = new CSVWriter(sw);
                Iterator it = propertyMap.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry<String, String> pairs = (Map.Entry) it.next();
                    writer.writeNext(new String[]{pairs.getKey(), pairs.getValue()});
                }
                writer.close();
            } catch (Exception ex) {
                LogUtil.error(getClass().getName(), ex, "");
            }
            String pluginProps = sw.toString();
            pluginDefaultProperties.setPluginProperties(pluginProps);
View Full Code Here

            }

            // form csv properties
            StringWriter sw = new StringWriter();
            try {
                CSVWriter writer = new CSVWriter(sw);
                Iterator it = propertyMap.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry<String, String> pairs = (Map.Entry) it.next();
                    writer.writeNext(new String[]{pairs.getKey(), pairs.getValue()});
                }
                writer.close();
            } catch (Exception ex) {
                LogUtil.error(getClass().getName(), ex, "");
            }
            String pluginProps = sw.toString();
            propertySetting.setValue(pluginProps);
View Full Code Here

    private CSVWriter csvWriter = null;
    private StringBuffer lastLine = null;
   
    public CsvWriter(Writer writer, Class<T> beanClass, char separator, char quotechar) throws IOException {
        csvWriter = new CSVWriter(new WriterWrapper(writer), separator, quotechar);
        mapping = new CsvFieldMapping<T>();
        mapping.setType(beanClass);
    }
View Full Code Here

   * Creates the directories required and open/create the file as a CSVWriter
   * @param filepath The filepath of the file to open/create as a string
   * @return The CSVWriter to write to the csv
   */
  public static CSVWriter openCSV(String filepath) {
    CSVWriter writer = null;
    //Open the csv file
    try {
      File file = new File(filepath);
      file.getParentFile().mkdirs();
      writer = new CSVWriter(new FileWriter(file), ',',
          CSVWriter.NO_QUOTE_CHARACTER);   
    } catch (IOException e) {
      System.err.println("Failed to open csv file.");
      System.exit(1);
    }
View Full Code Here

   * @param runningDataAggregates The aggregate data
   */
  private void writeRunningDataAggregatesAsAverageToCSV(LinkedHashMap<Integer,
      RunningData> runningDataAggregates) {
    //Open the csv file and write the header
    CSVWriter runningDataWriter = CSVWrapper.openCSV("../" +
      this.outputFolder + Strings.RUNNING_DATA_FILENAME);
    runningDataWriter.writeNext(new String[] {"Ticks", "Clique",
        "DeltaClique", "SuccessiveRatio"});
   
    //Average the stats and write them out
    for (Map.Entry<Integer, RunningData> entry :
      runningDataAggregates.entrySet()) {
      runningDataWriter.writeNext(new String[] {"" + entry.getKey(),
          "" + entry.getValue().clique /
          entry.getValue().getValuesAddedTogether(),
          "" + entry.getValue().deltaClique /
          entry.getValue().getValuesAddedTogether(),
          "" + entry.getValue().successiveRatio /
View Full Code Here

   * @param iterations The number of iterations aggregated
   */
  private void writeFinalPersonDataAggregatesAsAverageToCSV(HashMap<Coord,
      Person> finalPersonDataAggregates, int iterations) {
    //Open the csv file and write the header
    CSVWriter personDetailsWriter = CSVWrapper.openCSV("../" +
      this.outputFolder + Strings.FINAL_PERSON_DATA_FILENAME);
    personDetailsWriter.writeNext(new String[] {"TimesHeard",
        "FirstTimeHeard", "KnowledgeOfRumour"});
   
    //Average the stats and write them out
    for (Map.Entry<Coord, Person> entry :
      finalPersonDataAggregates.entrySet()) {
      personDetailsWriter.writeNext(new String[] {
          "" +
          entry.getValue().getTimesHeard() / (float)iterations,
          ""
          + entry.getValue().getFirstTimeHeard() / (float)iterations,
          "" +
View Full Code Here

        int index = 0;
        data[index] = "row/col";
        for (T t : columnKeys) {
            data[++index] = this.itemToString(t);
        }
        CSVWriter writer = new CSVWriter(new BufferedWriter(new FileWriter(destination)), ';');

        writer.writeNext(data);

        List<K> rowSet = new LinkedList<>(this.rows.keySet());

        //rows
        for (int j = 0; j < this.rows.size(); j++) {
            data[0] = this.itemToString(rowSet.get(j));
            //columns
            for (int i = 0; i < this.columns.size(); i++) {
                data[i + 1] = String.valueOf(this.matrix[j][i]);
            }
            writer.writeNext(data);
        }

        writer.close();
    }
View Full Code Here

        out.println(String.format("Query: %s infile %s delim '%s' quoted %s outfile %s batch-size %d",
                                   query,name(inputFileName),delim,quotes,name(outputFile),batchSize));

        CSVReader reader = createReader(inputFile, config);

        CSVWriter writer = createWriter(outputFile, config);

        int count;
        if (reader==null) {
            count = execute(query, writer);
        } else {
            count = executeOnInput(reader, query, writer, config, new ProgressReporter(inputFile,out));
        }
        out.println("Import statement execution created "+count+" rows of output.");
        if (reader!=null) reader.close();
        if (writer!=null) writer.close();
        return Continuation.INPUT_COMPLETE;
    }
View Full Code Here

    }

    private CSVWriter createWriter(File outputFile, Config config) throws IOException {
        if (outputFile==null) return null;
        FileWriter file = new FileWriter(outputFile);
        return config.isQuotes() ? new CSVWriter(file,config.getDelimChar(), Config.QUOTECHAR) : new CSVWriter(file,config.getDelimChar());
    }
View Full Code Here

TOP

Related Classes of au.com.bytecode.opencsv.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.