이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 37. Flatpack


Flatpack Component

The Flatpack component supports fixed width and delimited file parsing using the FlatPack library. Notice: This component only supports consuming from flatpack files to Object model. You can not (yet) write from Object model to flatpack format.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-flatpack</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

Copy to Clipboard Toggle word wrap

URI format

flatpack:[delim|fixed]:flatPackConfig.pzmap.xml[?options]
Copy to Clipboard Toggle word wrap
Or for a delimited file handler with no configuration file just use:
flatpack:someName[?options]
Copy to Clipboard Toggle word wrap
You can append query options to the URI in the following format, ?option=value&option=value&...

URI Options

Expand
Name Default Value Description
delimiter , The default character delimiter for delimited files.
textQualifier " The text qualifier for delimited files.
ignoreFirstRecord true Whether the first line is ignored for delimited files (for the column headers).
splitRows true As of Apache Camel 1.5, the component can either process each row one by one or the entire content at once.
allowShortLines false *Camel 2.9.3:* Allows for lines to be shorter than expected and ignores the extra characters.
ignoreExtraColumns false *Camel 2.9.3:* Allows for lines to be longer than expected and ignores the extra characters.

Examples

  • flatpack:fixed:foo.pzmap.xml creates a fixed-width endpoint using the foo.pzmap.xml file configuration.
  • flatpack:delim:bar.pzmap.xml creates a delimited endpoint using the bar.pzmap.xml file configuration.
  • flatpack:foo creates a delimited endpoint called foo with no file configuration.

Message Headers

Apache Camel will store the following headers on the IN message:
Expand
Header Description
camelFlatpackCounter The current row index. For splitRows=false the counter is the total number of rows.

Message Body

The component delivers the data in the IN message as a org.apache.camel.component.flatpack.DataSetList object that has converters for java.util.Map or java.util.List. Usually you want the Map if you process one row at a time (splitRows=true). Use List for the entire content (splitRows=false), where each element in the list is a Map. Each Map contains the key for the column name and its corresponding value.
For example to get the firstname from the sample below:
  Map row = exchange.getIn().getBody(Map.class);
  String firstName = row.get("FIRSTNAME");
Copy to Clipboard Toggle word wrap
However, you can also always get it as a List (even for splitRows=true). The same example:
  List data = exchange.getIn().getBody(List.class);
  Map row = (Map)data.get(0);
  String firstName = row.get("FIRSTNAME");
Copy to Clipboard Toggle word wrap

Header and Trailer records

The header and trailer notions in Flatpack are supported. However, you must use fixed record IDs:
  • header for the header record (must be lowercase)
  • trailer for the trailer record (must be lowercase)
The example below illustrates this fact that we have a header and a trailer. You can omit one or both of them if not needed.
    <RECORD id="header" startPosition="1" endPosition="3" indicator="HBT">
        <COLUMN name="INDICATOR" length="3"/>
        <COLUMN name="DATE" length="8"/>
    </RECORD>

    <COLUMN name="FIRSTNAME" length="35" />
    <COLUMN name="LASTNAME" length="35" />
    <COLUMN name="ADDRESS" length="100" />
    <COLUMN name="CITY" length="100" />
    <COLUMN name="STATE" length="2" />
    <COLUMN name="ZIP" length="5" />

    <RECORD id="trailer" startPosition="1" endPosition="3" indicator="FBT">
        <COLUMN name="INDICATOR" length="3"/>
        <COLUMN name="STATUS" length="7"/>
    </RECORD>
Copy to Clipboard Toggle word wrap

Using the endpoint

A common use case is sending a file to this endpoint for further processing in a separate route. For example:
  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
    <route>
      <from uri="file://someDirectory"/>
      <to uri="flatpack:foo"/>
    </route>

    <route>
      <from uri="flatpack:foo"/>
      ...
    </route>
  </camelContext>
Copy to Clipboard Toggle word wrap
You can also convert the payload of each message created to a Map for easy Bean Integration
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat