use of org.knime.core.data.DataCellDataInput in project knime-core by knime.
the class LargeBlobCell method getCellSerializer.
public static final DataCellSerializer<LargeBlobCell> getCellSerializer() {
return new DataCellSerializer<LargeBlobCell>() {
private final Random m_random;
{
long time = System.currentTimeMillis();
NodeLogger.getLogger(LargeBlobCell.class).debug("Using seed " + time);
m_random = new Random(time);
}
/**
* {@inheritDoc}
*/
@Override
public LargeBlobCell deserialize(final DataCellDataInput input) throws IOException {
int sizeOfCell = input.readInt();
CheckUtils.checkArgument(sizeOfCell >= 0, "Negative size %d", sizeOfCell);
for (int i = 0; i < sizeOfCell / 2; i++) {
input.readByte();
}
String identifier = input.readUTF();
for (int i = 0; i < sizeOfCell / 2; i++) {
input.readByte();
}
return new LargeBlobCell(identifier, LargeBlobCell.SIZE_OF_CELL);
}
/**
* {@inheritDoc}
*/
@Override
public void serialize(final LargeBlobCell cell, final DataCellDataOutput output) throws IOException {
output.writeInt(cell.m_sizeOfCell);
byte[] ar = new byte[cell.m_sizeOfCell / 2];
m_random.nextBytes(ar);
output.write(ar);
output.writeUTF(cell.m_identifier);
m_random.nextBytes(ar);
output.write(ar);
}
};
}
Aggregations