@Test public void testBlob() throws Exception { try (final Statement stmt = con.createStatement()) { stmt.executeUpdate("CREATE TABLE blobtest (id INT, b BLOB(64 K))"); stmt.execute("INSERT INTO blobtest VALUES (41, NULL)"); PreparedStatement ps = con.prepareStatement("INSERT INTO blobtest VALUES (?, ?)"); ps.setInt(1, 42); final byte[] buffer = new byte[4002]; IntStream.range(0, 4002).forEach((i) -> buffer[i] = (byte) ((i % 10) + 65)); buffer[1] = 0; ByteArrayInputStream bais = new ByteArrayInputStream(buffer); ps.setBlob(2, bais, 4002); ps.execute(); bais.close(); final ResultSet resultSet = stmt.executeQuery("select * from blobtest"); final ByteArrayOutputStream outStream = new ByteArrayOutputStream(); JdbcCommon.convertToAvroStream(resultSet, outStream, false); final byte[] serializedBytes = outStream.toByteArray(); assertNotNull(serializedBytes); final InputStream instream = new ByteArrayInputStream(serializedBytes); final DatumReader<GenericRecord> datumReader = new GenericDatumReader<>(); try (final DataFileStream<GenericRecord> dataFileReader = new DataFileStream<>(instream, datumReader)) { GenericRecord record = null; while (dataFileReader.hasNext()) { record = dataFileReader.next(record); Integer id = (Integer) record.get("ID"); Object o = record.get("B"); if (id == 41) { assertNull(o); } else { assertNotNull(o); assertTrue(o instanceof ByteBuffer); final byte[] blob = ((ByteBuffer) o).array(); assertEquals(4002, blob.length); assertEquals('C', blob[2]); } } } } }
public static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, boolean convertNames) throws SQLException, IOException { return convertToAvroStream(rs, outStream, null, null, convertNames); }
JdbcCommon { public static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, boolean convertNames) throws SQLException, IOException { return convertToAvroStream(rs, outStream, null, null, convertNames); } }
JdbcCommon { public static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, boolean convertNames) throws SQLException, IOException { return convertToAvroStream(rs, outStream, null, null, convertNames); }  }
JdbcCommon { public static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, boolean convertNames) throws SQLException, IOException { return convertToAvroStream(rs, outStream, null, null, convertNames); }  static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, boolean convertNames); static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, String recordName, boolean convertNames); static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, String recordName, ResultSetRowCallback callback, boolean convertNames); static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, String recordName, ResultSetRowCallback callback, final int maxRows, boolean convertNames); static void createEmptyAvroStream(final OutputStream outStream); static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, final AvroConversionOptions options, final ResultSetRowCallback callback); static Schema createSchema(final ResultSet rs); static Schema createSchema(final ResultSet rs, String recordName, boolean convertNames); static Schema createSchema(final ResultSet rs, AvroConversionOptions options); static String normalizeNameForAvro(String inputName); static void setParameters(final PreparedStatement stmt, final Map<String, String> attributes); static void setParameter(final PreparedStatement stmt, final String attrName, final int parameterIndex, final String parameterValue, final int jdbcType,
                              final String valueFormat); static DateTimeFormatter getDateTimeFormatter(String pattern); }
JdbcCommon { public static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, boolean convertNames) throws SQLException, IOException { return convertToAvroStream(rs, outStream, null, null, convertNames); }  static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, boolean convertNames); static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, String recordName, boolean convertNames); static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, String recordName, ResultSetRowCallback callback, boolean convertNames); static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, String recordName, ResultSetRowCallback callback, final int maxRows, boolean convertNames); static void createEmptyAvroStream(final OutputStream outStream); static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, final AvroConversionOptions options, final ResultSetRowCallback callback); static Schema createSchema(final ResultSet rs); static Schema createSchema(final ResultSet rs, String recordName, boolean convertNames); static Schema createSchema(final ResultSet rs, AvroConversionOptions options); static String normalizeNameForAvro(String inputName); static void setParameters(final PreparedStatement stmt, final Map<String, String> attributes); static void setParameter(final PreparedStatement stmt, final String attrName, final int parameterIndex, final String parameterValue, final int jdbcType,
                              final String valueFormat); static DateTimeFormatter getDateTimeFormatter(String pattern); static final Pattern LONG_PATTERN; static final Pattern SQL_TYPE_ATTRIBUTE_PATTERN; static final Pattern NUMBER_PATTERN; static final String MIME_TYPE_AVRO_BINARY; static final PropertyDescriptor NORMALIZE_NAMES_FOR_AVRO; static final PropertyDescriptor USE_AVRO_LOGICAL_TYPES; static final PropertyDescriptor DEFAULT_PRECISION; static final PropertyDescriptor DEFAULT_SCALE; }