Reputation: 1437
I am using univocity 2.9.1 file parser for a fixed width text file which is multi-schema.
I have setup the different record types using settings addFormatForLookahead method.
settings.addFormatForLookahead("11", headerFields);
settings.addFormatForLookahead("12", accountFields);
settings.addFormatForLookahead("13", footerFields);
The fields have been defined for the different record types.
I am able to parse the records when the data is good, using parseAll or with a row processor and beginParsing/parseNext/stopParsing.
This issue is when file contains incorrect data, the parser throws a TextParsingException and stops parsing. I would like the parser to continue parsing the rest of the file. I see a RetryableErrorHandler mentioned in documentation, but I cannot see how it applies in this scenario. I tried it and it didn't work.
ie
settings.setProcessorErrorHandler(new RetryableErrorHandler<ParsingContext>() {
@Override
public void handleError(DataProcessingException error, Object[] inputRow, ParsingContext context) {
//if there's an error in the first column, assign 50 and proceed with the record.
if(error.getColumnIndex() == 0){
setDefaultValue(50);
} else { //else keep the record anyway. Null will be used instead.
keepRecord();
}
}
});
I guess i can create a default FixedWidthField field with one field, which is full length. In this case, if it doesn't identify the header, account, or footer records then it will use the default field, and will continue parsing on unknown records.
Please advise.
Thanks, B
Upvotes: 1
Views: 304