CSVDataFrameWriter { public void writeToStream(DataFrame df, Writer out) throws IOException { String[] columnNames = df.getSchema().getColumnNames().toArray(new String[0]); final CsvWriterSettings settings = new CsvWriterSettings(); settings.setFormat(format); CsvWriter writer = new CsvWriter(out, settings); writer.writeHeaders(columnNames); for (Row curRow : df.getRowIterator()) { List<Object> rowValues = curRow.getVals(); writer.writeRow(rowValues); } writer.close(); } CSVDataFrameWriter();  CSVDataFrameWriter(String fieldDelimiter, String lineDelimiter); void writeToStream(DataFrame df, Writer out);  }
@Test public void writeToStream() throws Exception { StringWriter sb = new StringWriter(); DataFrame df = new DataFrame(); String[] col1 = {"a", "b"}; double[] col2 = {1.0, 2.0}; df.addColumn("col1", col1); df.addColumn("col2", col2); CSVDataFrameWriter writer = new CSVDataFrameWriter(); writer.writeToStream(df, sb); String out = sb.toString(); assertEquals(3, out.split("\n").length); assertTrue(out.contains("b")); }