我正在使用 CopyBook4Java 库,我可以在其中找到无法完全解决我的情况的解码选项,其中大型机签名显示字段BigDecimal
键入变量。下面你可以看到我的测试:
assertEquals(new BigDecimal("0.00"), typeConverter.to("00000000000000ä".getBytes(StandardCharsets.ISO_8859_1), 0, 15, 2, true));
assertEquals(new BigDecimal("-200541.00"), typeConverter.to("00000002005410ä".getBytes(StandardCharsets.ISO_8859_1), 0, 15, 2, true));
assertEquals(new BigDecimal("33258.91"), typeConverter.to("00000000332589A".getBytes(StandardCharsets.ISO_8859_1), 0, 15, 2, true));
CopyBookFieldSigningType.LAST_BYTE_EBCDIC_BIT5
给我处理响应的可能性,但不幸的是解码的值是错误的,特别是对于:
- 十进制字段 0.01-0.09
- 零值 0.00
- 负值,即-200541.00
我想我需要修改:
(signingType == CopyBookFieldSigningType.LAST_BYTE_EBCDIC_BIT5) {
byte res = (byte)(bytes[bytes.length -1] & 240); // Read last byte and zero first 4 bits of the result, 11110000
byte[] bytesCopy = Arrays.copyOf(bytes, bytes.length - 1);
if((byte)(res ^ 208) == 0 ||(byte)(res ^ 176) == 0) { // 208 = 11010000, 176 = 10110000
strValue = "-" + getString(bytesCopy, offset, length -1, removePadding, 1) + String.valueOf(bytes[bytes.length -1] & 15);
} else {
strValue = getString(bytesCopy, offset, bytesCopy.length, removePadding, 1) + String.valueOf(bytes[bytes.length -1] & 15);
}
}
我不知道如何为我的案例正确修改算法。有人可以建议我如何正确解码从大型机到BigDecimal
格式的响应吗?
在这里您可以使用单元测试检查我的存储库:https ://repl.it/@epredator/copybook4java#copybook4java/src/test/java/com/nordea/oss/copybook/converters/SignedDecimalToBigDecimalLastByteTest.java
下面你可以看到响应字帖的样本:
09 exchangerate PIC S9(6)V9(7).
09 accountBalance PIC S9(13)V9(2).
示例大型机响应:
20200931 1234567C ADAM1 NO ZOO TESTACCOUNT O, SAMPLE SITE1L
0212013000105101YYY SAMPLECO Currentacc EUR000000000000000000000332589A00000000000000ä00000002005410ä00000000332589A00000000000000ä00000000000000ä91193000105037XXX SAMPLECO Checkingac EUR000000000000000000002786655I00000000000000ä00000000000000ä00000000000000ä00000000000000ä00000000000000ä