I'm using Spring Batch in a project and I had to use FixedLengthTokenizer.
I configured it like this:
But my file is very large and there is too many different fields in each line, so I thought that the previous approach was not very readable. So, I created a new class called MapFixedLengthTokenizer with this implementation:Code:<bean id="myTokenizer" class="org.spring...FixedLengthTokenizer"> <property name="names" value="info1,info2,info3"/> <property name="columns" value="1-10,11-13,14-20"/> </bean>
I can now configure my tokenizer this way (more readable for longer lines, in my opinion):Code:public class MapFixedLengthTokenizer extends FixedLengthTokenizer { public void setTokenDefinitions(Map<String, Range> tokenDefinitions) { setNames(tokenDefinitions.keySet().toArray(new String[tokenDefinitions.keySet().size()])); setColumns(tokenDefinitions.values().toArray(new Range[tokenDefinitions.values().size()])); } }
Is there something in Spring Batch that could do this already? Is this a good way of achieving my readability goal or is there something that you would recommend more?Code:<bean id="dadosFuncionaisTokenizer" class="br.ufrn.sigrh.fitaespelho.batch.MapFixedLengthTokenizer"> <property name="tokenDefinitions"> <map> <entry key="INFO1" value="1-10"/> <entry key="INFO2" value="11-13"/> <entry key="INFO3" value="14-20"/> </map> </property> </bean>
Thanks for your attention.


Reply With Quote