我尝试运行使用java执行customerDownload的自动脚本。然而,当他们尝试比较时,realNumFields = 226但expNumFields = 5列,我不知道如何解决这个问题。请在下面建议我的代码:
protected void populateFields(L msgLine, List<String> values) throws FieldNotFoundException, ParseException, InvalidValueException {
if (values == null || values.isEmpty()) {
return;
}
if (expectAllFields) {
int expNumFields = this.fieldDefinitions.length;
int actualNumFields = values.size();
Preconditions.checkArgument(actualNumFields == expNumFields, "Values list of size " + actualNumFields
+ " is not the same as field definitions size "
+ expNumFields);
}
int idx = 0;
FieldParser parser = (FieldParser) getSerializationContext().getFieldOperator();
for (String strValue : values) {
FieldDefinition fDefinition = fieldDefinitions[idx];
parser.parseStringAndSetValue(msgLine, fDefinition.getFieldName(), strValue);
idx++;
}
}
public TextToMessageLineFactory(DelimitedFileSerializationContext<L> serializationContext) {
;
Preconditions.checkNotNull(serializationContext, "serialization context cannot be null");
this.serializationContext = serializationContext;
this.structure = serializationContext.getMessageStructure();
this.messageLineClass = this.structure.getMessageLineClass();
this.expectAllFields = serializationContext.isExpectAllFields();
FieldDefinitionsProvider fieldDefinitionsProvider = this.serializationContext.getFieldDefinitionsProvider();
fieldDefinitionsProvider = fieldDefinitionsProvider == null ? FieldDefinitionsProvider.ALL_FIELDS_DEFINITIONS_BY_INDEX_PROVIDER
: fieldDefinitionsProvider;
this.fieldDefinitions = fieldDefinitionsProvider.getFieldDefinitions(structure);
}
definitionProvider的字段为:
public FieldDefinition[] getFieldDefinitions(MessageLineStructure<? extends MessageLine> mls);
// @formatter:off
public static final FieldDefinitionsProvider
ALL_FIELDS_DEFINITIONS_BY_INDEX_PROVIDER =
new FieldDefinitionsProvider() {
@Override
public FieldDefinition[] getFieldDefinitions(MessageLineStructure<? extends MessageLine> mls) {
Preconditions.checkNotNull(mls,
"Message line structure cannot be null");
List<FieldDefinition> fieldDefinitions = mls.getFieldDefinitions(FieldDefinition.ByIndexComparator);
return fieldDefinitions.toArray(new FieldDefinition[fieldDefinitions.size()]);
}
};