/** * Writes a single cell to the current line, only quoting if needed. * <p> * When using this method, either {@link #writeNewLine()} or one of the {@code writeLine} * methods must be called at the end of the line. * * @param cell the cell to write * @return this, for method chaining * @throws UncheckedIOException if an IO exception occurs */ public CsvOutput writeCell(String cell) { writeCell(cell, false); return this; }
/** * 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(); }
csv.writeCell(SensitivityCsvLoader.REFERENCE_HEADER); csv.writeCell(SensitivityCsvLoader.TYPE_HEADER); csv.writeCell(SensitivityCsvLoader.TENOR_HEADER); if (containsDates) { csv.writeCell(SensitivityCsvLoader.DATE_HEADER); csv.writeCell(SensitivityCsvLoader.CURRENCY_HEADER); csv.writeCell(SensitivityCsvLoader.VALUE_HEADER); csv.writeLine(additionalHeaders);
Tenor tenor = ((TenoredParameterMetadata) pmd).getTenor(); double value = paramSens.getSensitivity().get(i); csv.writeCell(reference); csv.writeCell(type.getName()); csv.writeCell(tenor.toString()); if (containsDates) { csv.writeCell(pmd instanceof DatedParameterMetadata ? ((DatedParameterMetadata) pmd).getDate().toString() : ""); csv.writeCell(paramSens.getCurrency().getCode()); csv.writeCell(BigDecimal.valueOf(value).toPlainString()); csv.writeLine(additionalCells);
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()); }