파일 처리

파일을 입/출력을 처리하는 ItemReader와 ItemWriter는 프레임워크에서 기본 기능으로 제공하며 배치작업 xml에 작성하여 처리가 된다.

1. 파일 처리 Property

  • "resource" (파일 Path)

파일의 Path를 기술하는 속성이다.

<bean id="RBMdpLoadCustFile100" parent="RFix" scope="step">
    <property name="resource" value="file:///datafiles/bxmtest/rsample.dat" />
  • "encoding" (인코딩)

파일 Read / Write 시 처리하는 파일에 대한 Encoding 관련하여 처리하는 속성이다.

<bean id="RBMdpLoadCustFile100" parent="RFix" scope="step">
    <property name="resource" value="file:///datafiles/bxmtest/rsample.dat" />
    <property name="encoding" value="UTF-8" />
  • "strict" (파일 존재여부 확인)

파일의 존재여부를 확인하는 속성값으로 파일 존재여부에 따라서 에러/정상 처리를 할 수 있다.

  • true : Default 값으로 파일이 존재하지 않는 경우 에러처리

  • false : 파일이 존재하지 않아도 정상적으로 처리

<bean id="RBMdpLoadCustFile100" parent="RFix" scope="step">
    <property name="strict" value="true" />
</bean>
  • "appendAllowed" (파일 Append 여부)

    • true : 파일이 존재하지 않을 경우 파일을 생성하고, 존재하면 파일에 추가하여 레코드를 남긴다.

    • false : 파일이 존재하지 않을 경우 파일을 생성하고, 존재하면 Exception을 발생한다.

    • 해당 Property를 정의하지 않은 경우 : 파일이 존재하지 않을 경우 파일을 생성하고, 존재하면 OverWrite처리를 한다.

<bean id="RBMdpLoadCustFile100" parent="RFix" scope="step">
    <property name="appendAllowed" value="true" />
</bean>
  • "lineSeparator" (파일 개행처리)

파일 Read / Write시 Window, Unix Mode에 맞게 개행 처리를 할 수 있다. 기본적으로 파일 생성시는 배치가 실행되는 System 환경에 따라 Default 값으로 처리가 된다.

  • lineSeparator 설정 값

-  Carrige Return(CR) : &#xD
-  Line Feed(LF) : &#xA
  • Window Mode(LF/CR) 설정

<bean id="WBMdpWriteCustData100" parent="WFix" scope="step">
    <property name="lineSeparator" value="&#xD;&#xA;" />
    …
</bean>
  • Unix Mode

배치는 기본적으로 Unix 환경에서 실행함으로 설정이 필요하지 않다.

  • 라인이 없는 파일 처리

lineSeparator 값을 "" 즉, empty 값으로 설정하면 라인이 없는 파일도 처리할 수 있다.

2. Fixed 파일 Read

Fixed Format을 가진 파일 Read시 배치작업 xml 정의 방법

  • IO 작성

Fixed 파일 IO
Figure 1. Fixed 파일 IO
  • Read할 파일 Sample

IO의 필드에 정의되어 있는 Length만큼 파일의 데이터를 읽어온다. 아래의 파일 Sample은 IO에 정의된 Length 만큼 작성된 Sample이다. (공백은 '_'로 표시)

Fixed 파일 Sample
Figure 2. Fixed 파일 Sample
  • 배치 작업 xml

<bean id="RBMdpLoadCustFile100" parent="RFix" scope="step">
    <property name="resource" value="file:///datafiles/bxm/dat/rsample.dat" />
    <property name="encoding" value="UTF-8" />
    <property name="targetType" value="bxm.dft.smp.batch.bean.dto.MSmpMultiFileReadBtch01Dto" />
</bean>

3. Fixed 파일 Write

Fixed Format으로 파일 Write시 배치작업 xml 정의 방법

  • IO 작성

Fixed 파일 IO
Figure 3. Fixed 파일 IO
  • Write할 파일 Sample

IO의 필드에 정의되어 있는 Length만큼 파일의 데이터를 쓴다. 아래의 파일 Sample은 OMM에 정의된 Length 만큼 작성된 Sample이다. (공백은 '_'로 표시)

Fixed 파일 Sample
Figure 4. Fixed 파일 Sample
  • 배치 작업 xml

<bean id="WBMdpWriteCustData100" parent="WFix" scope="step">
    <property name="resource" value="file:///datafiles/bxm/dat/customer_data_wsample.dat" />
    <property name="encoding" value="UTF-8" />
    <property name="targetType" value="bxm.dft.smp.batch.bean.dto.MSmpMultiFileWriteBtch01Dto" />
</bean>

4. Delimited 파일 Read

Delimited Format을 가진 파일 Read시 배치작업 xml 정의 방법

  • IO 작성

Delimited 파일 IO
Figure 5. Delimited 파일 IO
  • Read할 파일 Sample

Read하려는 파일에서 배치작업 xml에 정의되어 있는 delimiter 값 ';' 으로 구분하여 처리할 수 있는 Sample

Delimited File Sample
Figure 6. Delimited File Sample
  • 배치 작업 xml

<bean id="RBMdpCustDataFiletoFile100" parent="RDelimit" scope="step">
    <property name="resource" value="file:///datafiles/bxm/dat/drsample.dat" />
    <property name="encoding" value="UTF-8" />
    <property name="delimiter" value=";" />
    <property name="targetType" value="bxm.dft.smp.batch.bean.dto.MSmpDelimitedToDBBtch01Dto" />
</bean>

5. Delimited 파일 Write

Delimited Format으로 파일 Write시 배치작업 xml 정의 방법

  • IO 작성

Delimited 파일 IO
Figure 7. Delimited 파일 IO
  • Write할 파일 Sample

IO에 정의되어 있는 필드 순서에 따라 파일 생성

Delimited 파일 Sample
Figure 8. Delimited 파일 Sample
  • 배치 작업 xml

<bean id="WBMdpCustDataFiletoFile100" parent="WDelimit" scope="step">
    <property name="resource" value="file:///datafiles/bxm/dat/dwsample.dat" />
    <property name="encoding" value="UTF-8" />
    <property name="delimiter" value=";" />
    <property name="targetType" value="bxm.dft.smp.batch.bean.dto.MSmpFixedToDelimitedBtch01Dto" />
</bean>

6. 배치 기본 파일 처리 외 Case 처리

다양한 파일 처리 유형은 '8장. 배치 파일 처리 유형 상세’에서 확인 할 수 있다.

SWLab Bankware Global
  • 전체
  • BXM
  • BXCM
  • BXCP
  • BXI
제품 선택 시 더 정확한 매뉴얼 가이드를 제공해드립니다.

Copyright© Bankwareglobal All Rights Reserved.