Search code examples
javaflat-filefixed-width

Parsing multi-line fixed-width files


I have a fixed-width flat file. To make matters worse, each line can either be a new record or a subrecord of the line above, identified by the first character on each line:

A0020SOME DESCRIPTION   MORE DESCRIPTION 922 2321      # Separate
A0021ANOTHER DESCRIPTIONMORE DESCRIPTION 23111442      # records
B0021ANOTHER DESCRIPTION   THIS TIME IN ANOTHER FORMAT # sub-record of record "0021"

I've tried using Flatworm which seems to be an excellent library for parsing fixed-width data. It's documentation, unfortunately, states:

"Repeating segments are supported only for delimited files"

(ibid, "Repeating segments").

I'd rather not write a custom parser for this. Is it (1) possible to do this in Flatworm or (2) is there a library providing such (multi-line, multi-sub-record) capabilities?


Solution

  • Have you looked at JRecordBind?

    http://jrecordbind.org/

    "JRecordBind supports hierarchical fixed length files: records of some type that are 'sons' of other record types."