Package com.csvreader

Examples of com.csvreader.CsvWriter


            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


    return new MongoInstance[0];
  }

  private void saveServers() {
    // save server preferences here
    CsvWriter writer = null;
    try {
      IPath libPath = getStateLocation();
      libPath = libPath.append("servers.cfg");
      File file = libPath.toFile();
      if (!file.exists()) {
        file.createNewFile();
      }
      writer = new CsvWriter(new FileWriter(file, false), ',');
      for (MongoInstance server : mongoInstances.values()) {
        writer.write(server.getName());
        writer.write(server.getHost());
        writer.write(String.valueOf(server.getPort()));
        writer.endRecord();
      }
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  }
View Full Code Here

     * @return
     */
    protected CsvWriter initializeWriter (Writer writer)
    {
        char delimiter = getCustomDelimiter();
        CsvWriter csvWriter = new CsvWriter(writer, delimiter);
        csvWriter.setTextQualifier(getTextQualifier());
        csvWriter.setForceQualifier(useQualifier());
        csvWriter.setComment(getCommentChar());
        return csvWriter;
    }
View Full Code Here

     */
    public String getTextRepresentation () {

        StringWriter sw = new StringWriter();
        try {
            CsvWriter clw = initializeWriter(sw);

            /*
            if (isFirstLineHeader() && header.size() > 0) {
                String[] headerArray = new String[header.size()];
                for (int i=0; i<header.size(); i++) {
                    headerArray[i] = header.get(i);
                }
                clw.writeRecord(headerArray);
            }
            */
            for (CSVRow row : rows) {
                if (row.isCommentLine()) {
                    clw.writeComment(row.getComment());
                } else {
                    clw.writeRecord(row.getEntriesAsArray());
                }
            }
            clw.close();
            sw.close();
        } catch (Exception e) {
            System.out.println("cannot write csv file");
            e.printStackTrace();
        } finally {
View Full Code Here

        for (int i = 1; i <= fileAmount; i++) {

            String outputFile = inputPath + File.separator + "inputFile-" + i + ".csv";
            // use FileWriter constructor that specifies open for appending
            CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), ',');

            for (int j = 0; j < recordAmount; j++) {
                writeRecord(csvOutput);
            }
            csvOutput.close();
        }
    }
View Full Code Here

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

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    CsvWriter writer = new CsvWriter(stream, '\t', Charset
        .forName("ISO-8859-1"));
    writer.write("data\r\nmore data");
    writer.write(" 3\t", false);
    writer.write(" 3\t");
    writer.write(" 3\t", true);
    writer.endRecord();
    writer.close();

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

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

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

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    CsvWriter writer = new CsvWriter(stream, ',', Charset
        .forName("ISO-8859-1"));
    writer.setForceQualifier(true);
    writer.write(" data ");
    writer.endRecord();
    writer.close();

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

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

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

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    CsvWriter writer = new CsvWriter(stream, ',', Charset
        .forName("ISO-8859-1"));
    Assert.assertEquals('\0', writer.getRecordDelimiter());
    writer.setRecordDelimiter(';');
    Assert.assertEquals(';', writer.getRecordDelimiter());
    writer.write("a;b");
    writer.endRecord();
    writer.close();

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

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

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

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    CsvWriter writer = new CsvWriter(stream, ',', Charset
        .forName("ISO-8859-1"));
    Assert.assertEquals(CsvWriter.ESCAPE_MODE_DOUBLED, writer
        .getEscapeMode());
    writer.setEscapeMode(CsvWriter.ESCAPE_MODE_BACKSLASH);
    Assert.assertEquals(CsvWriter.ESCAPE_MODE_BACKSLASH, writer
        .getEscapeMode());
    writer.write("1,2");
    writer.write("3");
    writer.write("blah \"some stuff in quotes\"");
    writer.endRecord();
    writer.setForceQualifier(true);
    writer.write("1,2");
    writer.write("3");
    writer.write("blah \"some stuff in quotes\"");
    writer.close();

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

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

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

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    CsvWriter writer = new CsvWriter(stream, ',', Charset
        .forName("ISO-8859-1"));
    writer.setEscapeMode(CsvWriter.ESCAPE_MODE_BACKSLASH);
    writer.setUseTextQualifier(false);
    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

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.