How to fill a DenseByteVectorCell from a byte[] in a custom node?


I'm rather new to Java and Knime, so I probably miss something obvious here...

What I'm trying to do is to display a byte[] in an output table of a custom node. For that purpose I am using a DenseByteVectorCell in my data table. I understood that I cannot create such a cell object directly but have to use DenseByteVectorCellFactory.createDataCell().

Creating a DenseByteVector from my byte[] in order to initialize the factory from that vector is not allowed, since DenseByteVector(final byte[] counts) is not public. So I initialized the factory with the length of my byte[] and tried to set the byte values one by one in a loop -- which works ok for byte values 0x00 to 0x7f but fails for values 0x80 to 0xff with "Only values 0...255 can be stored in the vector".

As far as I can see from the sources, this is because DenseByteVectorCellFactory.set(final int byteIndex, final byte byteVal) takes a byte (which is always signed in Java, isn't it?) and passes it to DenseByteVector.set(final int index, final int count), which expects an int value and complains about it being negative, when my original byte value is in the range 0x80 to 0xff.

To make a long story short: How am I supposed to fill a DenseByteVectorCell from a byte[] in my custom node (for byte values with the most significant bit set)?



I'm afraid there is now way around this bug for now.

In KNIME 2.9 the DenseByteVectorCellFactory will have two new setValue methods, with which the full byte range can be used.