我处理一些固定长度的数据。所以我使用 bindy 组件来处理这些数据。
该文件只有一条记录。记录具有页眉、多正文和页脚。
header record (total length : 20)
1 : record_type (length : 1)
VOLTE : service_type (length : 5)
20190515 : creation date (length : 8)
3 : custom_flag (length : 6)
3 body records (total length : 20)
2 : record_type (length : 1)
01012345678 : mobile number (length : 11)
20190515 : call start date (length : 8)
footer records (total length : 20)
3 : record_type (length : 1)
AAAA.DAT : FILE NAME (length : 19)
真实数据
1VOLTE20190515 32010123456782019051520101234567820190516201012345678201905173AAAA.DAT
我定义了如下数据格式。
标题
@FixedLengthRecord(length=20, paddingChar=' ')
public class VoLTEHeader {
@DataField(pos=1, length=1, trim=true)
String record_type;
@DataField(pos=2, length=5, trim=true)
String service_type;
@DataField(pos=7, length=8, trim=true)
String creation_date;
@DataField(pos=15, length=6, trim=true, align="R")
String custom_flag;
页脚
@FixedLengthRecord(length=20, paddingChar=' ')
public class VoLTEFooter {
@DataField(pos=1, length=1, trim=true)
String record_type;
@DataField(pos=2, length=19, trim=true)
String file_name;
身体
@FixedLengthRecord(length=20, header=VoLTEHeader.class, footer=VoLTEFooter.class)
public class VoLTEBody implements Serializable {
@DataField(pos=1, length=1,trim=true)
String record_type;
@DataField(pos=2, length=11,trim=true)
String mobile_number;
@DataField(pos=13, length=8,trim=true)
String call_start_date;
我执行了骆驼路线,但发生了异常。
java.lang.IllegalArgumentException: Size of the record: 100 is not equal to the value provided in the model: 20
at org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat.createModel(BindyFixedLengthDataFormat.java:295) ~[camel-bindy-2.23.2.jar:2.23.2]
at org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat.unmarshal(BindyFixedLengthDataFormat.java:209) ~[camel-bindy-2.23.2.jar:2.23.2]
at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:69) ~[camel-core-2.23.2.jar:2.23.2]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) [camel-core-2.23.2.jar:2.23.2]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.23.2.jar:2.23.2]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) [camel-core-2.23.2.jar:2.23.2]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) [camel-core-2.23.2.jar:2.23.2]
我不认为 fixedLengthDataFormat 一定需要在多行中创建。
我该如何解决这个问题?