@Test public void testExample() throws Exception { String[] directives = new String[]{ "write-as-csv body", }; List<Row> rows = Arrays.asList( new Row("int", 1).add("string", "this is, string") ); rows = TestingRig.execute(directives, rows); Assert.assertTrue(rows.size() == 1); Assert.assertEquals("1,\"this is, string\"", rows.get(0).getValue(2)); }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { try { final ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try (Writer out = new BufferedWriter(new OutputStreamWriter(bOut))) { CSVPrinter csvPrinter = new CSVPrinter(out, CSVFormat.DEFAULT); for (int i = 0; i < row.width(); ++i) { csvPrinter.print(row.getValue(i)); } csvPrinter.flush(); csvPrinter.close(); } catch (Exception e) { bOut.close(); } row.add(column, bOut.toString()); } catch (IOException e) { throw new DirectiveExecutionException(NAME, e.getMessage(), e); } } return rows; }
WriteAsCSV implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { try { final ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try (Writer out = new BufferedWriter(new OutputStreamWriter(bOut))) { CSVPrinter csvPrinter = new CSVPrinter(out, CSVFormat.DEFAULT); for (int i = 0; i < row.width(); ++i) { csvPrinter.print(row.getValue(i)); } csvPrinter.flush(); csvPrinter.close(); } catch (Exception e) { bOut.close(); } row.add(column, bOut.toString()); } catch (IOException e) { throw new DirectiveExecutionException(NAME, e.getMessage(), e); } } return rows; } }
WriteAsCSV implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { try { final ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try (Writer out = new BufferedWriter(new OutputStreamWriter(bOut))) { CSVPrinter csvPrinter = new CSVPrinter(out, CSVFormat.DEFAULT); for (int i = 0; i < row.width(); ++i) { csvPrinter.print(row.getValue(i)); } csvPrinter.flush(); csvPrinter.close(); } catch (Exception e) { bOut.close(); } row.add(column, bOut.toString()); } catch (IOException e) { throw new DirectiveExecutionException(NAME, e.getMessage(), e); } } return rows; }  }
WriteAsCSV implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { try { final ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try (Writer out = new BufferedWriter(new OutputStreamWriter(bOut))) { CSVPrinter csvPrinter = new CSVPrinter(out, CSVFormat.DEFAULT); for (int i = 0; i < row.width(); ++i) { csvPrinter.print(row.getValue(i)); } csvPrinter.flush(); csvPrinter.close(); } catch (Exception e) { bOut.close(); } row.add(column, bOut.toString()); } catch (IOException e) { throw new DirectiveExecutionException(NAME, e.getMessage(), e); } } return rows; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); }
WriteAsCSV implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { try { final ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try (Writer out = new BufferedWriter(new OutputStreamWriter(bOut))) { CSVPrinter csvPrinter = new CSVPrinter(out, CSVFormat.DEFAULT); for (int i = 0; i < row.width(); ++i) { csvPrinter.print(row.getValue(i)); } csvPrinter.flush(); csvPrinter.close(); } catch (Exception e) { bOut.close(); } row.add(column, bOut.toString()); } catch (IOException e) { throw new DirectiveExecutionException(NAME, e.getMessage(), e); } } return rows; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); static final String NAME; }