|
@@ -14,8 +14,6 @@ import java.util.BitSet;
|
|
*/
|
|
*/
|
|
public class BitValueMapper extends AbstractValueMapper<byte[]> {
|
|
public class BitValueMapper extends AbstractValueMapper<byte[]> {
|
|
|
|
|
|
- private final ByteBuffer buffer = ByteBuffer.allocate(4);
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
protected byte[] convert(ConnectorMapper connectorMapper, Object val) {
|
|
protected byte[] convert(ConnectorMapper connectorMapper, Object val) {
|
|
if (val instanceof BitSet) {
|
|
if (val instanceof BitSet) {
|
|
@@ -23,28 +21,22 @@ public class BitValueMapper extends AbstractValueMapper<byte[]> {
|
|
return bitSet.toByteArray();
|
|
return bitSet.toByteArray();
|
|
}
|
|
}
|
|
if (val instanceof Integer) {
|
|
if (val instanceof Integer) {
|
|
- synchronized (this){
|
|
|
|
- buffer.clear();
|
|
|
|
- buffer.putInt((Integer) val);
|
|
|
|
- buffer.flip();
|
|
|
|
- byte[] bytes = new byte[4];
|
|
|
|
- buffer.get(bytes);
|
|
|
|
- return bytes;
|
|
|
|
- }
|
|
|
|
|
|
+ ByteBuffer buffer = ByteBuffer.allocate(4);
|
|
|
|
+ buffer.putInt((Integer) val);
|
|
|
|
+ byte[] bytes = new byte[4];
|
|
|
|
+ buffer.get(bytes);
|
|
|
|
+ return bytes;
|
|
}
|
|
}
|
|
if (val instanceof Boolean) {
|
|
if (val instanceof Boolean) {
|
|
Boolean b = (Boolean) val;
|
|
Boolean b = (Boolean) val;
|
|
- synchronized (this){
|
|
|
|
- buffer.clear();
|
|
|
|
- buffer.putShort((short) (b ? 1 : 0));
|
|
|
|
- buffer.flip();
|
|
|
|
- byte[] bytes = new byte[2];
|
|
|
|
- buffer.get(bytes);
|
|
|
|
- return bytes;
|
|
|
|
- }
|
|
|
|
|
|
+ ByteBuffer buffer = ByteBuffer.allocate(2);
|
|
|
|
+ buffer.putShort((short) (b ? 1 : 0));
|
|
|
|
+ byte[] bytes = new byte[2];
|
|
|
|
+ buffer.get(bytes);
|
|
|
|
+ return bytes;
|
|
}
|
|
}
|
|
|
|
|
|
throw new ConnectorException(String.format("%s can not find type [%s], val [%s]", getClass().getSimpleName(), val.getClass(), val));
|
|
throw new ConnectorException(String.format("%s can not find type [%s], val [%s]", getClass().getSimpleName(), val.getClass(), val));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|