pfx-io Component

Overview

The pfx-io component provides file I/O utilities for integration routes: charset detection, file compression, virtual header parsing, and file-splitting helpers. All operations are producer-only.

URI pattern: pfx-io:method[?options]


Methods

Method

Description

detectCharset

Detect character encoding of the body (byte array or stream)

setupCharset

Apply charset configuration to the exchange

compress

Compress body into a ZIP or GZ archive

streamCompressedFile

Stream the contents of a compressed file

parseVirtualHeaders

Parse virtual headers in dataload format

parseValidationSchema

Parse a validation schema from the body

fileSplitHelper

Track line/file counters when splitting large files


Parameters

compress

Parameter

Type

Default

Description

compressionType

String

ZIP

Compression format: ZIP (ZIP archive) or GZ (GZIP stream)

outputFileName

String

--

File name inside the archive (e.g. data.csv)

compressedFileOutputPath

String

--

Write archive to disk instead of keeping in memory

useSystemTmpDir

Boolean

false

Write to system temp directory

updateCamelHeaders

Boolean

false

Update CamelFileName / CamelFilePath headers after compression

detectCharset / setupCharset

Parameter

Type

Default

Description

specifiedCharset

String

--

Override detected charset with a fixed value

streamCompressedFile

No parameters. Detects compression format from the file name (via CamelFileNameOnly or CamelAwsS3Key header):

  • .gz files: wraps body in GZIPInputStream

  • .zip files: wraps body in ZipInputStream (opens first entry)

  • Other extensions: no-op

parseVirtualHeaders

Parameter

Type

Default

Description

dataloadFileType

DataloadFileType

--

File type of the dataload (e.g., CSV, Excel). Used when parsing virtual headers in dataload routes.

fileSplitHelper

Parameter

Type

Default

Description

routeId

String

--

Route ID stored in exchange cache for tracking

incrementMode

Boolean

false

Increment file/line counters on each exchange

lineCounterHeader

String

LineCounter

Header name for current line count

fileCounterHeader

String

FileCounter

Header name for current file count

maxLinesForSplit

Integer

--

Max lines per output file

skipHeader

Boolean

false

Skip header row when splitting

incrementRows

Integer

--

Custom increment per exchange

fileNameTemplate

String

--

Template for generated output file names

fileNameResultHeader

String

StorageFileName

Header where the generated file name is stored


Examples

Compress a CSV body into a ZIP

XML
<routes xmlns="http://camel.apache.org/schema/spring">
    <route id="compressAndSend">
        <from uri="file:{{inbound.path}}"/>
        <to uri="pfx-io:compress?outputFileName=export.csv&amp;updateCamelHeaders=true"/>
        <to uri="sftp:{{sftp.host}}?username={{sftp.user}}&amp;password={{sftp.pass}}"/>
    </route>
</routes>

Detect charset before unmarshalling

XML
<to uri="pfx-io:detectCharset"/>
<to uri="pfx-io:setupCharset"/>
<to uri="pfx-csv:unmarshal?delimiter=,"/>

File split tracking

XML
<split>
    <tokenize token="&#10;" group="10000"/>
    <to uri="pfx-io:fileSplitHelper?routeId=myRoute&amp;incrementMode=true&amp;maxLinesForSplit=10000"/>
    <to uri="pfx-api:loaddata?objectType=DM&amp;dsUniqueName=MyDS&amp;mapper=myMapper"/>
</split>
<onCompletion onCompleteOnly="true">
    <to uri="pfx-api:flush?objectType=DM&amp;dsUniqueName=MyDS"/>
</onCompletion>

Common Pitfalls

  • compress keeps the archive in memory by default -- use compressedFileOutputPath or useSystemTmpDir for large files.

  • fileSplitHelper must be called inside a <split> block; it relies on exchange-level counters.

  • detectCharset returns the detected charset in a header -- call setupCharset immediately after to apply it.