/** * Writes a single CSV line to the underlying. * <p> * The boolean flag controls whether each entry is always quoted or only quoted when necessary. * <p> * This method writes each cell in the specified list to the underlying, followed by * a new line character. * * @param line the line to write * @param alwaysQuote when true, each column will be quoted, when false, quoting is selective * @throws UncheckedIOException if an IO exception occurs */ public void writeLine(List<String> line, boolean alwaysQuote) { ArgChecker.notNull(line, "line"); for (String cell : line) { writeCell(cell, alwaysQuote); } writeNewLine(); }
public void test_writeCell() { StringBuilder buf = new StringBuilder(); CsvOutput.standard(buf, "\n") .writeCell("a") .writeCell("x") .writeNewLine() .writeCell("b", true) .writeCell("y", true) .writeNewLine(); assertEquals(buf.toString(), "a,x\n\"b\",\"y\"\n"); }
public void test_exception() { Appendable throwingAppendable = new Appendable() { @Override public Appendable append(CharSequence csq, int start, int end) throws IOException { throw new IOException(); } @Override public Appendable append(char c) throws IOException { throw new IOException(); } @Override public Appendable append(CharSequence csq) throws IOException { throw new IOException(); } }; CsvOutput output = CsvOutput.standard(throwingAppendable, "\n"); assertThrows(UncheckedIOException.class, () -> output.writeCell("a")); assertThrows(UncheckedIOException.class, () -> output.writeNewLine()); }