|
@@ -4,6 +4,8 @@ import org.dbsyncer.common.spi.ConnectorMapper;
|
|
|
import org.dbsyncer.connector.AbstractValueMapper;
|
|
|
import org.dbsyncer.connector.ConnectorException;
|
|
|
|
|
|
+import java.util.BitSet;
|
|
|
+
|
|
|
/**
|
|
|
* @author AE86
|
|
|
* @version 1.0.0
|
|
@@ -18,6 +20,20 @@ public class VarBinaryValueMapper extends AbstractValueMapper<byte[]> {
|
|
|
|
|
|
@Override
|
|
|
protected byte[] convert(ConnectorMapper connectorMapper, Object val) {
|
|
|
+ if (val instanceof BitSet) {
|
|
|
+ BitSet bitSet = (BitSet) val;
|
|
|
+ return toByteArray(bitSet);
|
|
|
+ }
|
|
|
throw new ConnectorException(String.format("%s can not find type [%s], val [%s]", getClass().getSimpleName(), val.getClass(), val));
|
|
|
}
|
|
|
+
|
|
|
+ public byte[] toByteArray(BitSet bits) {
|
|
|
+ byte[] bytes = new byte[8];
|
|
|
+ for (int i = 0; i < bits.length(); i++) {
|
|
|
+ if (bits.get(i)) {
|
|
|
+ bytes[bytes.length - i / 8 - 1] |= 1 << (i % 8);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return bytes;
|
|
|
+ }
|
|
|
}
|