ByteArrayColumnTranslator extends ColumnWriterWithCharEncoding { @Override public String translate(JdbcResultRow rs, int column) throws SQLException, IOException { return toString((byte[]) rs.getFieldValue(column)); } ByteArrayColumnTranslator(); @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 testByteToString() throws Exception { JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", "SomeData".getBytes(), Types.ARRAY); String translated = translator.translate(row, 0); assertEquals("SomeData", translated); }
@Test public void testByteToStringEncoded() throws Exception { JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", "SomeData".getBytes("UTF-8"), Types.ARRAY); String translated = translator.translate(row, 0); assertEquals("SomeData", translated); }
@Test public void testByteToStringColName() throws Exception { JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", "SomeData".getBytes(), Types.ARRAY); String translated = translator.translate(row, "testField"); assertEquals("SomeData", translated); }
@Test public void testByteIncorrectObject() throws Exception { JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", new Integer(10), Types.ARRAY); try { translator.translate(row, "testField"); fail(); } catch(Exception ex) { } }