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());
}