pfx-io



Overview

The pfx-io component provides file I/O utilities for integration routes: charset detection, UTF-8 validation, 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

checkUtf

Decide whether the body is valid UTF-8 (deterministic verdict, not a guess)

compress

Compress body into a ZIP 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

checkUtf

No parameters.

Decodes the whole body as UTF-8 and reports whether every byte belongs to a well-formed sequence. This is a validity check, not a charset guess — the answer is the same for the same bytes on every run, and a single invalid byte anywhere in the content makes the answer false. The body is read in 8 KB chunks, so a large file costs no extra memory, and the body stays readable for the following steps.

Content

Verdict

Plain ASCII

true (ASCII is a subset of UTF-8)

UTF-8, with or without a BOM

true

Empty body

true

A single-byte encoding with high bytes (windows-1250, ISO-8859-1, …)

false

A multi-byte sequence cut off at the end of the file

false

Supported body types: GenericFile, File, Path, InputStream, String (already decoded text, always true) and byte[]. Any other body type gives false.

Output:

Name

Kind

Description

PfxIsUtf

Header (Boolean)

The verdict

CamelCharsetName

Exchange property

Set to UTF-8, only when the verdict is true

A negative verdict sets no charset — checkUtf never detects one. Chain pfx-io:setupCharset after it when the route must still read non-UTF-8 content.

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=,"/>

Read UTF-8 without detection, detect only when necessary

XML
<to uri="pfx-io:checkUtf"/>
<choice>
    <when>
        <simple>${header.PfxIsUtf} == false</simple>
        <to uri="pfx-io:setupCharset"/>
    </when>
</choice>
<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.

  • checkUtf answers one question only: is the content UTF-8? It does not fall back to detection, so a route that must read non-UTF-8 content has to call setupCharset itself on a false verdict.

  • Run checkUtf on the final bytes. A base64-encoded or compressed body must be decoded and decompressed first — otherwise the verdict describes the transport wrapper, not the text.