Spring Batch - FlatFileItemReader \001 delimiter issue

烈酒焚心 提交于 2019-12-23 05:33:20

问题


I am working on a Spring batch application where i am using FlatFileItemReader to read the file with delimiter ~ or | and its working fine and its calling the processor once read is completed.

But when i try to use the delimiter as \001 the processor is not called and i am not getting any error also in the console.(Linux environment)

Example file format:

0002~000000000000000470~000006206210008078~PR~7044656907~7044641561~~~~240082202~~~ENG~CH~~19940926~D~~~AL~~~P~USA

This is my reader configuration.

    <property name="resource" value="#{stepExecutionContext['fileResource']}" />
    <!-- <property name="linesToSkip" value="1"></property> -->

    <property name="lineMapper">
        <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
            <property name="lineTokenizer">
                <bean
                    class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                    <property name="delimiter" value="${file.delimiter}"/>
                    <property name="names" value="sor_id,sor_cust_id,acct_id,cust_role_type_cd,cust_full_nm,mailg_adr_line_1,mailg_adr_line_2,mailg_city_nm,mailg_geo_st_cd,mailg_full_pstl_cd,mailg_cntry_cd,mailg_adr_desc,phy_adr_line_1,phy_adr_line_2,phy_city_nm,phy_geo_st_cd,phy_full_pstl_cd,phy_cntry_cd,phy_adr_desc,home_phn_num,work_phn_num,mobile_phn_num,email_adr_txt,ssn,cust_tax_idn_num,gndr_cd,martl_cd,lang_cd,acct_stat_cd,cust_brth_dt,acct_open_dt,sor_acct_stat_cd,sor_acct_stat_desc,vld_phn_num_ind,prod_cd,prft_ctr_cd,bus_legl_strc_cd,acct_use_cd,cntry_of_origin_cd" />
                </bean>
            </property>
            <property name="fieldSetMapper">
                <bean class="com.cap1.cdi.batch.SrcMasterFieldSetMapper" />
            </property>
        </bean>
    </property>

</bean>

Is anyone else faced the same kind of issue?

Regards, Shankar


回答1:


I am going to answer my own question.

The actual issue was control character was used as delimiter in linux (^A)

In Java when i use string.split("\u0001") it was working. Also passing the same to Spring batch flatfileitemreader as delimiter it works like a charm.

Thanks Shankar.



来源:https://stackoverflow.com/questions/28744449/spring-batch-flatfileitemreader-001-delimiter-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!