use of org.knime.core.table.io.ReadableDataInputStream in project knime-core by knime.
the class DictEncodedDataCellInOutDelegateTest method testReadAdapterCell.
@Test
public void testReadAdapterCell() throws IOException, ParserConfigurationException, SAXException, XMLStreamException {
// This calls readDataCell twice, once for the AdapterCell and once for the contained cell.
final var xmlString = "<dummyXML>Test</dummyXML>";
final var innerCell = XMLCellFactory.create(xmlString);
@SuppressWarnings("unchecked") final var cell = new MyAdapterCell(innerCell, XMLValue.class);
final IDataRepository dataRepository = null;
final IWriteFileStoreHandler fileStoreHandler = new ValueSchemaTest.DummyWriteFileStoreHandler();
final var baseBuffer = new ByteArrayOutputStream();
final var outStream = new DataOutputStream(baseBuffer);
try (final var out = new DictEncodedDataCellDataOutputDelegator(fileStoreHandler, outStream)) {
out.writeDataCell(cell);
final var classNames = DictEncodedDataCellDataInputDelegator.getSerializedCellNames(cell).split(";");
assertEquals(2, classNames.length);
assertEquals(cell.getClass().getName(), classNames[0]);
assertEquals(innerCell.getClass().getName(), classNames[1]);
final var inStream = new ReadableDataInputStream(new ByteArrayInputStream(baseBuffer.toByteArray()));
try (final var in = new DictEncodedDataCellDataInputDelegator(dataRepository, inStream, DictEncodedDataCellDataInputDelegator.getSerializedCellNames(cell))) {
in.readDataCell();
}
}
}
use of org.knime.core.table.io.ReadableDataInputStream in project knime-core by knime.
the class DictEncodedDataCellInOutDelegateTest method testReadDataCellWithoutClassNameThrowsException.
@Test(expected = IllegalStateException.class)
public void testReadDataCellWithoutClassNameThrowsException() throws IOException, ParserConfigurationException, SAXException, XMLStreamException {
final var xmlString = "<dummyXML>Test</dummyXML>";
final var cell = XMLCellFactory.create(xmlString);
final IDataRepository dataRepository = null;
final IWriteFileStoreHandler fileStoreHandler = new ValueSchemaTest.DummyWriteFileStoreHandler();
final var baseBuffer = new ByteArrayOutputStream();
final var outStream = new DataOutputStream(baseBuffer);
try (final var out = new DictEncodedDataCellDataOutputDelegator(fileStoreHandler, outStream)) {
out.writeDataCell(cell);
final var inStream = new ReadableDataInputStream(new ByteArrayInputStream(baseBuffer.toByteArray()));
try (final var in = new DictEncodedDataCellDataInputDelegator(dataRepository, inStream, "")) {
// throws because no cell class name was specified in constructor
in.readDataCell();
}
}
}
use of org.knime.core.table.io.ReadableDataInputStream in project knime-core by knime.
the class DictEncodedDataCellInOutDelegateTest method testWriteReadDataCell.
private static void testWriteReadDataCell(final DataCell cell) throws IOException {
final IDataRepository dataRepository = null;
final IWriteFileStoreHandler fileStoreHandler = new ValueSchemaTest.DummyWriteFileStoreHandler();
final var baseBuffer = new ByteArrayOutputStream();
final var outStream = new DataOutputStream(baseBuffer);
try (final var out = new DictEncodedDataCellDataOutputDelegator(fileStoreHandler, outStream)) {
out.writeDataCell(cell);
final var inStream = new ReadableDataInputStream(new ByteArrayInputStream(baseBuffer.toByteArray()));
try (final var in = new DictEncodedDataCellDataInputDelegator(dataRepository, inStream, DictEncodedDataCellDataInputDelegator.getSerializedCellNames(cell))) {
final var readCell = in.readDataCell();
assertEquals(cell, readCell);
}
}
}
Aggregations