StringColumnTranslator extends FormattableColumnTranslator implements ColumnWriter { @Override public void write(JdbcResultRow rs, int column, OutputStream out) throws SQLException, IOException { IOUtils.write(toString(rs.getFieldValue(column)), out, Charset.defaultCharset()); } StringColumnTranslator(); @Override String translate(JdbcResultRow rs, int column); @Override String translate(JdbcResultRow rs, String columnName); @Override void write(JdbcResultRow rs, int column, OutputStream out); @Override void write(JdbcResultRow rs, String columnName, OutputStream out);  }
@Test public void testStringWrite() throws Exception { JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", "SomeData", Types.VARCHAR); StringWriter writer = new StringWriter(); try (OutputStream out = new WriterOutputStream(writer)) { translator.write(row, 0, out); } String translated = writer.toString(); assertEquals("SomeData", translated); }
@Test public void testStringWrite_ByName() throws Exception { JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", "SomeData", Types.VARCHAR); StringWriter writer = new StringWriter(); try (OutputStream out = new WriterOutputStream(writer)) { translator.write(row, "testField", out); } String translated = writer.toString(); assertEquals("SomeData", translated); }