use of org.knime.core.data.blob.BinaryObjectDataCell in project knime-core by knime.
the class DataCellToJavaConversionTest method testBinaryObject.
/**
* Test BinaryObjectDataCell -> InputStream conversion.
*
* @throws Exception When something went wrong
*/
@Test
public void testBinaryObject() throws Exception {
/* retrieve converter from DataCellToJavaConverterRegistry */
final Optional<? extends DataCellToJavaConverterFactory<? extends DataValue, InputStream>> factory = DataCellToJavaConverterRegistry.getInstance().getConverterFactories(BinaryObjectDataCell.TYPE, InputStream.class).stream().findFirst();
assertTrue(factory.isPresent());
final DataCellToJavaConverter<DataCell, InputStream> converter = (DataCellToJavaConverter<DataCell, InputStream>) factory.get().create();
assertNotNull(converter);
final BinaryObjectCellFactory cellFactory = new BinaryObjectCellFactory();
assertTrue(converter.convert(cellFactory.create(new byte[] { 4, 2 })) instanceof InputStream);
/* convert a BinaryObjectDataCell */
InputStream stream = converter.convert(cellFactory.create(new byte[] { 4, 2 }));
assertEquals(stream.read(), 4);
assertEquals(stream.read(), 2);
stream.close();
}
Aggregations