Question
What generic and extensible solutions exist to convert a data file to fixed-width file?
The data file format can be CSV, XML, or plain text, as exported by JasperReports.
Background
The fields are listed as follows:
Field # Field Name Format Type Size Required
1 Customer RJ/ZF N 1 Y
2 Account RJ/SF N 5 Y
3 Location LJ/SF AN 10 Y
4 Agreement YN A 1 Y
...
55 Election CCYYMMDD N 8 N
Where: RJ
is Right Justified, ZF
is Zero Filled, SF
is Space Filled, YN
is Y
or N
, N
is numeric-only, A
is alphabetic, and AN
is alpha-numeric.
Each field has a specific start and end position in the record and each record exists on a single line.
Ideas
1st solution:
- Export the data file in XML format.
- Codify the 55 fixed-width definitions in XML.
- Create an XSL template to transform the data file to the fixed-width file.
2nd solution:
- Use JRecord with JasperReports.
3rd solution:
- Codify each field using a Java expression inside the JRXML template.
Commentary
Of these solutions, I prefer the 1st.
Any other possibilities? Any software that can perform this task?