Examples of CsvWriter


Examples of au.com.bytecode.opencsv.CSVWriter

        // failing string
        fields[4] = "Joe said, \"This is a test of a \nlong broken string,\" and Sally said, \"I bet it won't work.\" ";
        // working string
        // fields[4] = "Joe said, \"This is a test of a \nlong broken string,\" and Sally said, \"I bet it won't work.\"";

        CSVWriter writer = new CSVWriter(new FileWriter(filePath));
        writer.writeNext(fields); // let's make 3 rows so we can see it cleanly in Excel.
        writer.writeNext(fields);
        writer.writeNext(fields);
        writer.close();

        testRawCsvRead(fields[4]);
        testMappingStrategyRead(fields[4]);

        System.out.println("\nComplete.  File written out to " + filePath);
View Full Code Here

Examples of au.com.bytecode.opencsv.CSVWriter

    return data;
  }
 
  static public String toCsvFormat(Object input) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    StringWriter writer = new StringWriter();
    CSVWriter csvPrinter = new CSVWriter(writer);

    Class<? extends Object> c = input.getClass();
    Method methods[] = c.getMethods();
    Vector<String> v = new Vector<String>();
    for (Method method : methods) {
      if (!method.getName().startsWith("get")) {
        continue;
      }
      Object object = method.invoke(input, (Object[]) null);
      if (object == null) {
        v.add("");
      }
      else {
        String value = "Unknown type for " + method.getName();
        if (object instanceof String) {
          value = (String) object;
        }
        if (object instanceof Integer) {
          value = ((Integer) object).toString();
        }
        if (object instanceof Float) {
          value = ((Float) object).toString();
        }
        if (object instanceof Double) {
          value = ((Float) object).toString();
        }
        if (object instanceof Date) {
          value = Format.getDate((Date) object);
        }
        v.add(value);
      }
    }
    String tokens[] = new String[v.size()];
    v.copyInto(tokens);
    csvPrinter.writeNext(tokens);
    return writer.toString();
  }
View Full Code Here

Examples of au.com.bytecode.opencsv.CSVWriter

    public TabularWriter(PrintWriter out, String format) {
        this.out = out;
        this.format = format;

        if (CSV.equals(format)) {
            csvWriter = new CSVWriter(out);
        }
    }
View Full Code Here

Examples of au.com.bytecode.opencsv.CSVWriter

  public static boolean exportSecrets(Context context,List<Secret> secrets) {
    // An array to hold the rows that will be written to the CSV file.
    String[] row = new String[] {
        COL_DESCRIPTION, COL_USERNAME, COL_PASSWORD, COL_EMAIL, COL_NOTES
    };
    CSVWriter writer = null;
    boolean success = false;

    try {
      writer = new CSVWriter(new FileWriter(SECRETS_FILE_NAME_CSV));

      // Write descriptive headers.
      writer.writeNext(row);

      // Write out each secret.
      for (Secret secret : secrets) {
        row[0] = secret.getDescription();
        row[1] = secret.getUsername();
        row[2] = secret.getPassword(true)// true: forExport
        row[3] = secret.getEmail();
        row[4] = secret.getNote();

        // NOTE: writeNext() handles nulls in row[] gracefully.
        writer.writeNext(row);
        success = true;
      }
    } catch (Exception ex) {
      Log.e(LOG_TAG, "exportSecrets", ex);
    } finally {
      try {if (null != writer) writer.close();} catch (IOException ex) {}
    }

    return success;
  }
View Full Code Here

Examples of au.com.bytecode.opencsv.CSVWriter

  void writeNextAndClose(String[] csvRecord) {
    //actually writes a line to the app engine file, but doesn't finalize it, so not persisted in console, but it's there
    try {
      //CSVWriter writer = new CSVWriter(new BufferedWriter(pw1), ',', '"', "\r\n");
      StringWriter sw = new StringWriter();
      CSVWriter writer = new CSVWriter(sw, ',', '"', "\r\n");
      writer.flush();
      writer.writeNext(csvRecord);
      writer.close();
      RosieRecords rr = new RosieRecords();
      log.info("writing out csv record:" + sw.toString());
      rr.setValue(sw.toString());
      Date now = new Date();
      rr.setTimestamp(now);
View Full Code Here

Examples of au.com.bytecode.opencsv.CSVWriter

  public static void writeCsv(List<String[]> csvData, String fileName) throws IOException {
    if (csvData == null) {
      throw new IllegalArgumentException("Cannot write null CSV data to file.");
    }

    CSVWriter writer = null;
    try {
      writer = new CSVWriter(new FileWriter(fileName));
      for (String[] line : csvData) {
        writer.writeNext(line);
      }
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  }
View Full Code Here

Examples of au.com.bytecode.opencsv.CSVWriter

  private void writerFile(List<? extends Exportable> list, String fileName) {

    List<String[]> data = new ArrayList<String[]>();

    try {
      CSVWriter writer = new CSVWriter(new FileWriter(fileName), ';',
          CSVWriter.NO_QUOTE_CHARACTER);

      for (Exportable item : list)
        data.add(item.toCsv());

      writer.writeAll(data);
      writer.close();
    } catch (Exception e) {
      logger.error("writerFile", e);
    }

  }
View Full Code Here

Examples of au.com.bytecode.opencsv.CSVWriter

        return null;
    }

    public void sendContent( OutputStream out, Range range, Map<String, String> params, String contentType ) throws IOException, NotAuthorizedException, BadRequestException {
        PrintWriter pw = new PrintWriter(out);
        CSVWriter writer = new CSVWriter(pw);
        List<Vehicle> vehicles = vehicleDao.getAllVehicles();
        for( Vehicle v : vehicles ) {
            output(v,writer);
        }
        pw.flush();
View Full Code Here

Examples of au.com.bytecode.opencsv.CSVWriter

  public static void writeCsv(List<String[]> csvData, String fileName) throws IOException {
    if (csvData == null) {
      throw new IllegalArgumentException("Cannot write null CSV data to file.");
    }

    CSVWriter writer = null;
    try {
      writer = new CSVWriter(new FileWriter(fileName));
      for (String[] line : csvData) {
        writer.writeNext(line);
      }
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  }
View Full Code Here

Examples of au.com.bytecode.opencsv_voltpatches.CSVWriter

import au.com.bytecode.opencsv_voltpatches.CSVWriter;

public class TestVoltTableUtil extends Mockito {
    @Test
    public void testCSVNullConversion() throws IOException {
        CSVWriter writer = mock(CSVWriter.class);
        ColumnInfo[] columns = new ColumnInfo[] {new ColumnInfo("", VoltType.BIGINT),
                                                 new ColumnInfo("", VoltType.FLOAT),
                                                 new ColumnInfo("", VoltType.DECIMAL),
                                                 new ColumnInfo("", VoltType.STRING),
                                                 new ColumnInfo("", VoltType.TIMESTAMP),
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.