Announcement Announcement Module
Collapse
No announcement yet.
FixedLengthTokenizer using maps Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FixedLengthTokenizer using maps

    I'm using Spring Batch in a project and I had to use FixedLengthTokenizer.

    I configured it like this:

    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>
    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:
    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()])); 
        }
    
    }
    I can now configure my tokenizer this way (more readable for longer lines, in my opinion):

    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>
    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?

    Thanks for your attention.

  • #2
    david

    do u have complete example for this, i new to spring batch, i hve to read fixed length flat file with 500 fields in each row.
    thx
    GK

    Comment


    • #3
      Maybe you can externalize fields definition in a configuration file, create a FactoryBean for FixedLengthTokenizer that take as property the configuration files and return a new object.

      Comment


      • #4
        Originally posted by bellabax View Post
        Maybe you can externalize fields definition in a configuration file, create a FactoryBean for FixedLengthTokenizer that take as property the configuration files and return a new object.
        hi Bellabax, thanks
        do you have any example for this.

        i have tried using Beanio for fixed length mapping. i dont hnow whether it ll affect perfomance since i have to prosses 5 million records at a time ,each record ll have 450 to 500 columns it it.

        thanks
        GK

        Comment

        Working...
        X