title: How to custom Spring Batch DelimitedLineTokenizer
body: <p>I have two file types to insert in database.</p>
  
  <p>Format are : aa;bb;cc and aa;bb;cc;dd;ee</p>
  
  <p>This is my FlatFileItemReader :</p>
  
  <pre><code>    &lt;bean name="readerContractToAddIntoPRV" class="org.springframework.batch.item.file.FlatFileItemReader"&gt;
          &lt;property name="comments" value="#" /&gt;
          &lt;property name="linesToSkip" value="1" /&gt;
          &lt;property name="strict" value="false" /&gt;
          &lt;property name="lineMapper"&gt;
              &lt;bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper"&gt;
                  &lt;property name="fieldSetMapper"&gt;
                      &lt;bean class="net.wl.batchs.fieldSetMapper.LineToCreateIntoPrvFieldSetMapper" /&gt;
                  &lt;/property&gt;
                  &lt;property name="lineTokenizer"&gt;
                      &lt;bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"&gt;
                          &lt;property name="delimiter" value=";"/&gt;
                          &lt;property name="names" value="aa,bb,cc,dd,ee" /&gt;
                      &lt;/bean&gt;
                  &lt;/property&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>I want a setup that works for both types of files.</p>
  
  <p>For the moment, I have this :  </p>
  
  <blockquote>
    <p>org.springframework.batch.item.file.transform.IncorrectTokenCountException:
    Incorrect number of tokens found in record: expected 3 actual 5</p>
  </blockquote>
  
  <p>Do you have any ideas?</p>
  
  <p>Thank you.</p>
  
  <p>Edit : After correction :</p>
  
  <pre><code>&lt;bean name="readerContractToAddIntoPRV" class="org.springframework.batch.item.file.FlatFileItemReader"&gt;
      &lt;property name="comments" value="#" /&gt;
      &lt;property name="linesToSkip" value="1" /&gt; 
      &lt;property name="strict" value="false" /&gt;
      &lt;property name="lineMapper"&gt;
          &lt;bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper" p:lineTokenizer-ref="multilineFileTokenizer"&gt;
              &lt;property name="fieldSetMapper"&gt;
                  &lt;bean class="net.wl.batchs.fieldSetMapper.LineToCreateIntoPrvFieldSetMapper" /&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="multilineFileTokenizer" class="org.springframework.batch.item.file.transform.PatternMatchingCompositeLineTokenizer"&gt;
    &lt;property name="tokenizers"&gt;
      &lt;map&gt;
        &lt;entry key="*;*;*;*;*" value-ref="NSCE_ICCID_MSISDN_LOGIN_PWD"/&gt;
        &lt;entry key="*;*;*" value-ref="NSCE_ICCID_MSISDN"/&gt;
        &lt;entry key="*" value-ref="headerDefault"/&gt;
      &lt;/map&gt;
    &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="parentLineTokenizer" class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer" abstract="true"&gt;
      &lt;property name="delimiter" value=";"/&gt;
  &lt;/bean&gt;
  &lt;bean id="NSCE_ICCID_MSISDN_LOGIN_PWD" parent="parentLineTokenizer"&gt;
      &lt;property name="names" value="nsce,iccid,msisdn,login,pwd" /&gt;
  &lt;/bean&gt;
  &lt;bean id="NSCE_ICCID_MSISDN" parent="parentLineTokenizer"&gt;
      &lt;property name="names" value="nsce,iccid,msisdn" /&gt;
  &lt;/bean&gt;
  &lt;bean id="headerDefault" parent="parentLineTokenizer"&gt;
      &lt;property name="names" value="nsce,iccid,msisdn" /&gt;
  &lt;/bean&gt;
  </code></pre>