Package org.supercsv.io

Examples of org.supercsv.io.CsvListWriter


    public void open(final Serializable checkpoint) throws Exception {
        SupportLogger.LOGGER.tracef("Open CsvItemWriter with checkpoint %s, which is ignored for CsvItemWriter.%n", checkpoint);
        if (beanType == null) {
            throw SupportLogger.LOGGER.invalidReaderWriterProperty(null, BEAN_TYPE_KEY);
        } else if (java.util.List.class.isAssignableFrom(beanType)) {
            delegateWriter = new CsvListWriter(getOutputWriter(writeMode, stepContext), getCsvPreference());
        } else if (java.util.Map.class.isAssignableFrom(beanType)) {
            delegateWriter = new CsvMapWriter(getOutputWriter(writeMode, stepContext), getCsvPreference());
        } else {
            delegateWriter = new CsvBeanWriter(getOutputWriter(writeMode, stepContext), getCsvPreference());
        }
View Full Code Here


    public void open(final Serializable checkpoint) throws Exception {
        SupportLogger.LOGGER.tracef("Open CsvItemWriter with checkpoint %s, which is ignored for CsvItemWriter.%n", checkpoint);
        if (beanType == null) {
            throw SupportLogger.LOGGER.invalidCsvPreference(null, BEAN_TYPE_KEY);
        } else if (java.util.List.class.isAssignableFrom(beanType)) {
            delegateWriter = new CsvListWriter(getOutputWriter(), getCsvPreference());
        } else if (java.util.Map.class.isAssignableFrom(beanType)) {
            delegateWriter = new CsvMapWriter(getOutputWriter(), getCsvPreference());
        } else {
            delegateWriter = new CsvBeanWriter(getOutputWriter(), getCsvPreference());
        }
View Full Code Here

  @Override
  public String marshal(CsvTable table) {
    StringWriter sw = new StringWriter();
    try {
      CsvListWriter clw = new CsvListWriter(sw, CsvPreference.STANDARD_PREFERENCE);

        clw.write(table.getHeader());
     
        if(table.isLastEmpty()) {
        table.remove(table.size() - 1);
      }
     
      for (CsvRow row : table) {
        clw.write(row);
      }
     
      clw.close();
      sw.close();
    } catch (Exception e) {
      throw new RuntimeException("Unmarshelling of CSV Table failed.", e);
    }
    return sw.toString();
View Full Code Here

  /**
   * @param schema Used to generate column headers.
   */
  public CsvSink(Writer writer, Schema schema) throws IOException {
    this(new CsvListWriter(writer, ALWAYS_QUOTE), schema);
  }
View Full Code Here

  /**
   * @param schema Used to generate column headers.
   */
  public TsvSink(Writer writer, Schema schema) throws IOException {
    super(new CsvListWriter(writer, CsvPreference.TAB_PREFERENCE), schema);
  }
View Full Code Here

        }

    }

    public static void flushTriples(Iterable<KiWiTriple> tripleBacklog, OutputStream out) throws IOException {
        CsvListWriter writer = new CsvListWriter(new OutputStreamWriter(out), CsvPreference.STANDARD_PREFERENCE);

        // reuse the same array to avoid unnecessary object allocation
        Object[] rowArray = new Object[10];
        List<Object> row = Arrays.asList(rowArray);

        for(KiWiTriple t : tripleBacklog) {
            rowArray[0] = t.getId();
            rowArray[1] = t.getSubject();
            rowArray[2] = t.getPredicate();
            rowArray[3] = t.getObject();
            rowArray[4] = t.getContext();
            rowArray[5] = t.getCreator();
            rowArray[6] = t.isInferred();
            rowArray[7] = t.isDeleted();
            rowArray[8] = t.getCreated();
            rowArray[9] = t.getDeletedAt();

            writer.write(row, tripleProcessors);
        }
        writer.close();
    }
View Full Code Here

    }



    public static void flushNodes(Iterable<KiWiNode> nodeBacklog, OutputStream out) throws IOException {
        CsvListWriter writer = new CsvListWriter(new OutputStreamWriter(out), nodesPreference);

        // reuse the same array to avoid unnecessary object allocation
        Object[] rowArray = new Object[10];
        List<Object> row = Arrays.asList(rowArray);

        for(KiWiNode n : nodeBacklog) {
            if(n instanceof KiWiUriResource) {
                KiWiUriResource u = (KiWiUriResource)n;
                createNodeList(rowArray, u.getId(), u.getClass(), u.stringValue(), null, null, null, null, null, null, u.getCreated());
            } else if(n instanceof KiWiAnonResource) {
                KiWiAnonResource a = (KiWiAnonResource)n;
                createNodeList(rowArray, a.getId(), a.getClass(), a.stringValue(), null, null, null, null, null, null, a.getCreated());
            } else if(n instanceof KiWiIntLiteral) {
                KiWiIntLiteral l = (KiWiIntLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), l.getDoubleContent(), l.getIntContent(), null, null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiDoubleLiteral) {
                KiWiDoubleLiteral l = (KiWiDoubleLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), l.getDoubleContent(), null, null, null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiBooleanLiteral) {
                KiWiBooleanLiteral l = (KiWiBooleanLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), null, null, null, l.booleanValue(), l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiDateLiteral) {
                KiWiDateLiteral l = (KiWiDateLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), null, null, l.getDateContent(), null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiStringLiteral) {
                KiWiStringLiteral l = (KiWiStringLiteral)n;

                Double dbl_value = null;
                Long   lng_value = null;
                if(l.getContent().length() < 64 && NumberUtils.isNumber(l.getContent()))  {
                    try {
                        dbl_value = Double.parseDouble(l.getContent());
                        lng_value = Long.parseLong(l.getContent());
                    } catch (NumberFormatException ex) {
                        // ignore, keep NaN
                    }
                }
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), dbl_value, lng_value, null, null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else {
                log.warn("unknown node type, cannot flush to import stream: {}", n.getClass());
            }

            writer.write(row, nodeProcessors);
        }
        writer.close();
    }
View Full Code Here



    public static InputStream flushTriples(Iterable<KiWiTriple> tripleBacklog) throws IOException {
        StringWriter out = new StringWriter();
        CsvListWriter writer = new CsvListWriter(out, CsvPreference.STANDARD_PREFERENCE);

        // reuse the same array to avoid unnecessary object allocation
        Object[] rowArray = new Object[10];
        List<Object> row = Arrays.asList(rowArray);

        for(KiWiTriple t : tripleBacklog) {
            rowArray[0] = t.getId();
            rowArray[1] = t.getSubject();
            rowArray[2] = t.getPredicate();
            rowArray[3] = t.getObject();
            rowArray[4] = t.getContext();
            rowArray[5] = t.getCreator();
            rowArray[6] = t.isInferred();
            rowArray[7] = t.isDeleted();
            rowArray[8] = t.getCreated();
            rowArray[9] = t.getDeletedAt();

            writer.write(row, tripleProcessors);
        }
        writer.close();

        return IOUtils.toInputStream(out.toString());
    }
View Full Code Here



    public static InputStream flushNodes(Iterable<KiWiNode> nodeBacklog) throws IOException {
        StringWriter out = new StringWriter();
        CsvListWriter writer = new CsvListWriter(out, nodesPreference);

        // reuse the same array to avoid unnecessary object allocation
        Object[] rowArray = new Object[10];
        List<Object> row = Arrays.asList(rowArray);

        for(KiWiNode n : nodeBacklog) {
            if(n instanceof KiWiUriResource) {
                KiWiUriResource u = (KiWiUriResource)n;
                createNodeList(rowArray, u.getId(), u.getClass(), u.stringValue(), null, null, null, null, null, null, u.getCreated());
            } else if(n instanceof KiWiAnonResource) {
                KiWiAnonResource a = (KiWiAnonResource)n;
                createNodeList(rowArray, a.getId(), a.getClass(), a.stringValue(), null, null, null, null, null, null, a.getCreated());
            } else if(n instanceof KiWiIntLiteral) {
                KiWiIntLiteral l = (KiWiIntLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), l.getDoubleContent(), l.getIntContent(), null, null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiDoubleLiteral) {
                KiWiDoubleLiteral l = (KiWiDoubleLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), l.getDoubleContent(), null, null, null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiBooleanLiteral) {
                KiWiBooleanLiteral l = (KiWiBooleanLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), null, null, null, l.booleanValue(), l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiDateLiteral) {
                KiWiDateLiteral l = (KiWiDateLiteral)n;
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), null, null, l.getDateContent(), null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else if(n instanceof KiWiStringLiteral) {
                KiWiStringLiteral l = (KiWiStringLiteral)n;

                Double dbl_value = null;
                Long   lng_value = null;
                if(l.getContent().length() < 64 && NumberUtils.isNumber(l.getContent()))  {
                    try {
                        dbl_value = Double.parseDouble(l.getContent());
                        lng_value = Long.parseLong(l.getContent());
                    } catch (NumberFormatException ex) {
                        // ignore, keep NaN
                    }
                }
                createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), dbl_value, lng_value, null, null, l.getDatatype(), l.getLocale(), l.getCreated());
            } else {
                log.warn("unknown node type, cannot flush to import stream: {}", n.getClass());
            }

            writer.write(row, nodeProcessors);
        }
        writer.close();

        return IOUtils.toInputStream(out.toString());
    }
View Full Code Here

    return count - 1; // sans header row
  }

  private String getFormattedStr(String[] vals) {
    StringWriter strWriter = new StringWriter();
    CsvListWriter writer = new CsvListWriter(strWriter, csvPreference);
    if (vals.length > 0) {
      try {
        writer.write(vals);
      } catch (IOException e) {
        beeLine.error(e);
      } finally {
        IOUtils.closeStream(writer);
      }
View Full Code Here

TOP

Related Classes of org.supercsv.io.CsvListWriter

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.