Search in sources :

Example 1 with BinaryObjectDataCell

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();
}
Also used : DataCellToJavaConverter(org.knime.core.data.convert.java.DataCellToJavaConverter) InputStream(java.io.InputStream) BinaryObjectCellFactory(org.knime.core.data.blob.BinaryObjectCellFactory) DataCell(org.knime.core.data.DataCell) BinaryObjectDataCell(org.knime.core.data.blob.BinaryObjectDataCell) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)1 Test (org.junit.Test)1 DataCell (org.knime.core.data.DataCell)1 BinaryObjectCellFactory (org.knime.core.data.blob.BinaryObjectCellFactory)1 BinaryObjectDataCell (org.knime.core.data.blob.BinaryObjectDataCell)1 DataCellToJavaConverter (org.knime.core.data.convert.java.DataCellToJavaConverter)1