This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch feature/CAMEL-23789-wave1-multi-dsl-docs in repository https://gitbox.apache.org/repos/asf/camel.git
commit 2593c3c90c38303568eed586ddc8e01d96a55ca8 Author: Claus Ibsen <[email protected]> AuthorDate: Wed Jun 17 19:09:57 2026 +0200 CAMEL-23789: Make File component docs multi-DSL friendly (Wave 1) Co-Authored-By: Claude <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../camel-file/src/main/docs/file-component.adoc | 138 +++++++++++++++++++-- 1 file changed, 130 insertions(+), 8 deletions(-) diff --git a/components/camel-file/src/main/docs/file-component.adoc b/components/camel-file/src/main/docs/file-component.adoc index 4c8f3cdb7433..767c8ac054b3 100644 --- a/components/camel-file/src/main/docs/file-component.adoc +++ b/components/camel-file/src/main/docs/file-component.adoc @@ -465,6 +465,10 @@ files, by setting a property on the exchange with the key `Exchange.CHARSET_NAME`. For example, in the route below, we set the property with a value from a message header. +[tabs] +==== +Java:: ++ [source,java] ---- from("file:inbox") @@ -474,6 +478,42 @@ from("file:inbox") .to("file:outbox"); ---- +XML:: ++ +[source,xml] +---- +<route> + <from uri="file:inbox"/> + <convertBodyTo type="byte[]" charset="iso-8859-1"/> + <to uri="bean:myBean"/> + <setProperty name="CamelCharsetName"> + <header>someCharsetHeader</header> + </setProperty> + <to uri="file:outbox"/> +</route> +---- + +YAML:: ++ +[source,yaml] +---- +- route: + from: + uri: file:inbox + steps: + - convertBodyTo: + type: "byte[]" + charset: iso-8859-1 + - to: + uri: bean:myBean + - setProperty: + name: CamelCharsetName + header: someCharsetHeader + - to: + uri: file:outbox +---- +==== + We suggest keeping things simpler, so if you pick up files with the same encoding, and want to write the files in a specific encoding, then favor to use the `charset` option on the endpoints. @@ -576,14 +616,7 @@ YAML:: ---- ==== -To use `report.txt` as the filename you have to do: - -[source,java] ----- -from("direct:report").setHeader(Exchange.FILE_NAME, constant("report.txt")).to( "file:target/reports"); ----- - -... the same as above, but with `CamelFileName`: +To use `report.txt` as the filename you have to do (using the `CamelFileName` header): [tabs] ==== @@ -692,11 +725,33 @@ See also section <<File2-WritingDoneFiles,_writing done files_>> below. If you want only to consume files when a _done file_ exists, then you can use the `doneFileName` option on the endpoint. +[tabs] +==== +Java:: ++ [source,java] ---- from("file:bar?doneFileName=done"); ---- +XML:: ++ +[source,xml] +---- +<from uri="file:bar?doneFileName=done"/> +---- + +YAML:: ++ +[source,yaml] +---- +- from: + uri: file:bar + parameters: + doneFileName: done +---- +==== + It will only consume files from the _bar_ folder if a _done file_ exists in the same directory as the target files. Camel will automatically delete the _done file_ when it's done consuming the files. @@ -754,11 +809,33 @@ After you have written a file, you may want to write an additional _done file_ a to indicate to others that the file is finished and has been written. To do that, you can use the `doneFileName` option on the file producer endpoint. +[tabs] +==== +Java:: ++ [source,java] ---- .to("file:bar?doneFileName=done"); ---- +XML:: ++ +[source,xml] +---- +<to uri="file:bar?doneFileName=done"/> +---- + +YAML:: ++ +[source,yaml] +---- +- to: + uri: file:bar + parameters: + doneFileName: done +---- +==== + This will create a file named `done` in the same directory as the target file. @@ -935,11 +1012,33 @@ Camel supports Idempotent Consumer directly within the component, so it will skip already processed files. This feature can be enabled by setting the `idempotent=true` option. +[tabs] +==== +Java:: ++ [source,java] ---- from("file://inbox?idempotent=true").to("..."); ---- +XML:: ++ +[source,xml] +---- +<from uri="file://inbox?idempotent=true"/> +---- + +YAML:: ++ +[source,yaml] +---- +- from: + uri: file://inbox + parameters: + idempotent: true +---- +==== + Camel uses the absolute file name as the idempotent key, to detect duplicate files. You can customize this key by using an expression in the idempotentKey option. For example, to use both @@ -1113,11 +1212,33 @@ See the URI options above for more information. The sample below demonstrates how to use it: +[tabs] +==== +Java:: ++ [source,java] ---- from("file://inbox?antInclude=**/*.txt").to("..."); ---- +XML:: ++ +[source,xml] +---- +<from uri="file://inbox?antInclude=**/*.txt"/> +---- + +YAML:: ++ +[source,yaml] +---- +- from: + uri: file://inbox + parameters: + antInclude: "**/*.txt" +---- +==== + === Sorting Strategies Camel supports pluggable sorting strategies. They are described below. @@ -1262,6 +1383,7 @@ If you want to use the Camel Error Handler to deal with any exception occurring in the file consumer, then you can enable the `bridgeErrorHandler` option as shown below: +._Java-only: `onException` error handler configuration is Java DSL specific_ [source,java] ---- // to handle any IOException being thrown
