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 |
|---|---|
|
|
Detect character encoding of the body (byte array or stream) |
|
|
Apply charset configuration to the exchange |
|
|
Compress body into a ZIP or GZ archive |
|
|
Stream the contents of a compressed file |
|
|
Parse virtual headers in dataload format |
|
|
Parse a validation schema from the body |
|
|
Track line/file counters when splitting large files |
Parameters
compress
|
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
String |
|
Compression format: |
|
|
String |
-- |
File name inside the archive (e.g. |
|
|
String |
-- |
Write archive to disk instead of keeping in memory |
|
|
Boolean |
|
Write to system temp directory |
|
|
Boolean |
|
Update |
detectCharset / setupCharset
|
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
String |
-- |
Override detected charset with a fixed value |
streamCompressedFile
No parameters. Detects compression format from the file name (via CamelFileNameOnly or CamelAwsS3Key header):
-
.gzfiles: wraps body inGZIPInputStream -
.zipfiles: wraps body inZipInputStream(opens first entry) -
Other extensions: no-op
parseVirtualHeaders
|
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
DataloadFileType |
-- |
File type of the dataload (e.g., CSV, Excel). Used when parsing virtual headers in dataload routes. |
fileSplitHelper
|
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
String |
-- |
Route ID stored in exchange cache for tracking |
|
|
Boolean |
|
Increment file/line counters on each exchange |
|
|
String |
|
Header name for current line count |
|
|
String |
|
Header name for current file count |
|
|
Integer |
-- |
Max lines per output file |
|
|
Boolean |
|
Skip header row when splitting |
|
|
Integer |
-- |
Custom increment per exchange |
|
|
String |
-- |
Template for generated output file names |
|
|
String |
|
Header where the generated file name is stored |
Examples
Compress a CSV body into a ZIP
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="compressAndSend">
<from uri="file:{{inbound.path}}"/>
<to uri="pfx-io:compress?outputFileName=export.csv&updateCamelHeaders=true"/>
<to uri="sftp:{{sftp.host}}?username={{sftp.user}}&password={{sftp.pass}}"/>
</route>
</routes>
Detect charset before unmarshalling
<to uri="pfx-io:detectCharset"/>
<to uri="pfx-io:setupCharset"/>
<to uri="pfx-csv:unmarshal?delimiter=,"/>
File split tracking
<split>
<tokenize token=" " group="10000"/>
<to uri="pfx-io:fileSplitHelper?routeId=myRoute&incrementMode=true&maxLinesForSplit=10000"/>
<to uri="pfx-api:loaddata?objectType=DM&dsUniqueName=MyDS&mapper=myMapper"/>
</split>
<onCompletion onCompleteOnly="true">
<to uri="pfx-api:flush?objectType=DM&dsUniqueName=MyDS"/>
</onCompletion>
Common Pitfalls
-
compresskeeps the archive in memory by default -- usecompressedFileOutputPathoruseSystemTmpDirfor large files. -
fileSplitHelpermust be called inside a<split>block; it relies on exchange-level counters. -
detectCharsetreturns the detected charset in a header -- callsetupCharsetimmediately after to apply it.