Modified: websites/production/camel/content/file2.html
==============================================================================
--- websites/production/camel/content/file2.html (original)
+++ websites/production/camel/content/file2.html Fri Aug 25 10:20:13 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: File2
@@ -86,516 +75,134 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="File2-FileComponent">File
Component</h2><p>The File component provides access to file systems, allowing
files to be processed by any other Camel <a shape="rect"
href="components.html">Components</a> or messages from other components to be
saved to disk.</p><h3 id="File2-URIformat">URI format</h3><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[file:directoryName[?options]
-]]></script>
-</div></div><p>or</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[file://directoryName[?options]
-]]></script>
-</div></div><p>Where <strong><code>directoryName</code></strong>
represents the underlying file directory.</p><p>You can append query options to
the URI in the following format,
<strong><code>?option=value&option=value&...</code></strong></p><div
class="confluence-information-macro confluence-information-macro-tip"><p
class="title">Only directories</p><span class="aui-icon aui-icon-small
aui-iconfont-approve confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Camel supports only endpoints
configured with a starting directory. So
the <strong><code>directoryName</code></strong> must be a directory. If
you want to consume a single file only, you can use the
<strong>fileName</strong> option e.g., by setting
<strong><code>fileName=thefilename</code></strong>. Also, the starting
directory must not contain dynamic expressions
with <strong><code>${}</code></strong> placeholders. Again use the
<strong><code>fileName</code></stron
g> option to specify the dynamic part of the filename.</p></div></div><div
class="confluence-information-macro confluence-information-macro-warning"><p
class="title">Avoid reading files currently being written by another
application</p><span class="aui-icon aui-icon-small aui-iconfont-error
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Beware the JDK File IO API is a
bit limited in detecting whether another application is currently
writing/copying a file. And the implementation can be different depending on OS
platform as well. This could lead to that Camel thinks the file is not locked
by another process and start consuming it. Therefore you have to do you own
investigation what suites your environment. To help with this Camel provides
different <strong><code>readLock</code></strong> options and
<strong><code>doneFileName</code></strong> option that you can use. See also
the section <em>Consuming files from folders where others drop fil
es directly</em>.</p></div></div><h3 id="File2-URIOptions">URI Options</h3><h4
id="File2-Common">Common</h4><div class="confluenceTableSmall"><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>autoCreate</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Automatically create missing
directories in the file's path name. For the file consumer, that means creating
the starting directory. For the file producer, it means the directory the files
should be written to.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>bufferSize</code></p></td><td colspan="1"
rowspan="1" class="confluen
ceTd"><p><code>128kb</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Write buffer sized in bytes.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>fileName</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Use <a shape="rect"
href="expression.html">Expression</a> such as <a shape="rect"
href="file-language.html">File Language</a> to dynamically set the filename.
For consumers, it's used as a filename filter. For producers, it's used to
evaluate the filename to write. If an expression is set, it take precedence
over the <strong><code>CamelFileName</code></strong> header.
(<strong>Note:</strong> The header itself can also be an <a shape="rect"
href="expression.html">Expression</a>). The expression options support both
<strong><code>String</code></strong> and
<strong><code>Expression</code></strong> types. If the expression is a
<strong><code>Strin
g</code></strong> type, it is <strong>always</strong> evaluated using the <a
shape="rect" href="file-language.html">File Language</a>. If the expression is
an <strong><code>Expression</code></strong> type, the specified
<strong><code>Expression</code></strong> type is used - this allows you, for
instance, to use <a shape="rect" href="ognl.html">OGNL</a>
expressions.</p><p>For the consumer, you can use it to filter filenames, so you
can for instance consume today's file using the <a shape="rect"
href="file-language.html">File Language</a> syntax:
<strong><code>mydata-${date:now:yyyyMMdd}.txt</code></strong>. From
<strong>Camel 2.11</strong> onward the producers support the
<strong><code>CamelOverruleFileName</code></strong> header which takes
precedence over any existing <strong><code>CamelFileName</code></strong>
header; the <strong><code>CamelOverruleFileName</code></strong> is a header
that is used only once, and makes it easier as this avoids to temporary store
<strong><code>Came
lFileName</code></strong> and have to restore it
afterwards.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>flatten</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Flatten is used to flatten the file name
path to strip any leading paths, so it's just the file name. This allows you to
consume recursively into sub-directories, but when you eg write the files to
another directory they will be written in a single directory. Setting this to
<code>true</code> on the producer enforces that any file name received in
<strong><code>CamelFileName</code></strong> header will be stripped for any
leading paths.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>charset</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.9.3:</strong> this opt
ion is used to specify the encoding of the file. You can use this on the
consumer, to specify the encodings of the files, which allow Camel to know the
charset it should load the file content in case the file content is being
accessed. Likewise when writing a file, you can use this option to specify
which charset to write the file as well. See further below for a examples and
more important details.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>copyAndDeleteOnRenameFail</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9</strong>:
whether to fallback and do a copy and delete file, in case the file could not
be renamed directly. This option is not available for the <a shape="rect"
href="ftp2.html">FTP</a> component.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>renameUsingCopy</code></p></td><td
colspan="1" rowspan="1
" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.13.1</strong>: Perform
rename operations using a copy and delete strategy. This is primarily used in
environments where the regular rename operation is unreliable e.g., across
different file systems or networks. This option takes precedence over the
<strong><code>copyAndDeleteOnRenameFail</code></strong> parameter that will
automatically fall back to the copy and delete strategy, but only after
additional delays.</p></td></tr></tbody></table></div></div>
-
-
-<h4 id="File2-Consumer">Consumer</h4><div class="confluenceTableSmall"><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>initialDelay</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>1000</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Milliseconds before polling the
file/directory starts.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>delay</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>500</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Milliseconds before the next poll of the
file/directory.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>useFixedDela
y</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Controls if fixed delay or fixed rate is used. See <a
shape="rect" class="external-link"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html"
rel="nofollow">ScheduledExecutorService</a> in JDK for details.</p><p>In
<strong>Camel 2.7.x</strong> or older the default value is
<strong><code>false</code>. </strong></p><p>From<strong> Camel 2.8</strong>
onward the default value is
<strong><code>true</code>.</strong></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>runLoggingLevel</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>TRACE</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> The
consumer logs a start/complete log line when it polls. This option allows you
to configure the logging level for that.</p></td></tr><
tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>recursive</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>If a directory, will look for files in all
the sub-directories as well.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>delete</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>If <strong><code>true</code></strong>, the file will be
deleted <strong>after</strong> it is processed
successfully.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>noop</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>If <strong><code>true</code></strong>, the file is not
moved or deleted in any way. This option is good for readonly data, or for <a
shap
e="rect" href="etl.html">ETL</a> type requirements. If
<strong><code>noop=true</code></strong>, Camel will set
<strong><code>idempotent=true</code></strong> as well, to avoid consuming the
same files over and over again.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>preMove</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="expression.html">Expression</a> (such as <a shape="rect"
href="file-language.html">File Language</a>) used to dynamically set the
filename when moving it <strong>before</strong> processing. For example to move
in-progress files into the <strong><code>order</code></strong> directory set
this value to <strong><code>order</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>move</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>.camel</code></p></td><td
colspan="
1" rowspan="1" class="confluenceTd"><p><a shape="rect"
href="expression.html">Expression</a> (such as <a shape="rect"
href="file-language.html">File Language</a>) used to dynamically set the
filename when moving it <strong>after</strong> processing. To move files into a
<strong><code>.done</code></strong> subdirectory just enter
<strong><code>.done</code></strong>.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>moveFailed</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><a shape="rect"
href="expression.html">Expression</a> (such as <a shape="rect"
href="file-language.html">File Language</a>) used to dynamically set a
different target directory when moving files <em>in case of</em> processing
(configured via <code>move</code> defined above) failed.</p><p>For example, to
move files into a <strong><code>.error</code></strong> subdirectory use:
<strong><code>.error
</code></strong>.</p><p><strong>Note</strong>: When moving the files to the
“fail” location Camel will <strong>handle</strong> the error and
will not pick up the file again.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>include</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Is used to include files, if filename
matches the regex pattern <span>(matching is case in-sensitive from Camel
</span><strong>2.17</strong><span>
onward</span><span>).</span></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>exclude</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Is used to exclude files, if filename
matches the regex pattern (matching is case in-sensitive from Camel
<strong>2.17</strong> onward).</p></td></tr><tr><td colspan="1" rowspan="
1" class="confluenceTd"><p><code>antInclude</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong> Ant style
filter inclusion, for example
<strong><code>antInclude=*</code><code>/</code><code>.txt</code></strong>.
Multiple inclusions may be specified in comma-delimited format. See <a
shape="rect" href="#File2-FilteringusingANTpathmatcher">below</a> for more
details about ant path filters.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>antExclude</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong> Ant style
filter exclusion. If both <strong><code>antInclude</code></strong> and
<strong><code>antExclude</code></strong> are used,
<strong><code>antExclude</code></strong> takes precedence over
<strong><code>antInclude</code>
</strong>. Multiple exclusions may be specified in comma-delimited format. See
<a shape="rect" href="#File2-FilteringusingANTpathmatcher">below</a> for more
details about ant path filters.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>antFilterCaseSensitive</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong>
Ant style filter which is case sensitive or not.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>idempotent</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Option to use the <a shape="rect"
href="idempotent-consumer.html">Idempotent Consumer</a> EIP pattern to let
Camel skip already processed files. Will by default use a memory based LRUCache
that holds 1000 entries. If <strong><code>noop=true</code></strong
> then idempotent will be enabled as well to avoid consuming the same files
> over and over again.</p></td></tr><tr><td colspan="1" rowspan="1"
> class="confluenceTd"><p><code>idempotentKey</code></p></td><td colspan="1"
> rowspan="1" class="confluenceTd"><p><code>Expression</code></p></td><td
> colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong>
> To use a custom idempotent key. By default the absolute path of the file is
> used. You can use the <a shape="rect" href="file-language.html">File
> Language</a>, for example to use the file name and file size, you can
> do:</p><div class="code panel pdl" style="border-width: 1px;"><div
> class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[idempotentKey=${file:name}-${file:size}]]></script>
-</div></div></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>idempotentRepository</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>A pluggable repository <a
shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/IdempotentRepository.html"><code>org.apache.camel.spi.IdempotentRepository</code></a>
which by default use <strong><code>MemoryMessageIdRepository</code></strong>
if none is specified and <strong><code>idempotent</code></strong> is
<strong><code>true</code>.</strong></p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>inProgressRepository</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>memory</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>A pluggable in-progress
repository <a shape="rect" class="external-link" href="http://camel
.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/IdempotentRepository.html"><code>org.apache.camel.spi.IdempotentRepository</code></a>
. The in-progress repository is used to account the current in progress files
being consumed. By default a memory based repository is
used.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>filter</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Pluggable filter as a
<strong><code>org.apache.camel.component.file.GenericFileFilter</code></strong>
class. Will skip files if filter returns <strong><code>false</code></strong> in
its <strong><code>accept()</code></strong> method. More details in section
below.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>filterDirectory</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" cl
ass="confluenceTd"><p><strong>Camel 2.18</strong>: Filters the directory based
on <a shape="rect" href="simple.html">Simple</a> language. For example to
filter on current date, you can use a simple date pattern such
as <strong><code>${date:now:yyyMMdd</code>}.</strong></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>filterFile</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.18:</strong> Filters the
file based on <a shape="rect" href="simple.html">Simple</a> language. For
example to filter on file size, you can use <strong><code>${file}:size
> 5000</code></strong>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>shuffle</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.16:</strong> To shuffle the
list of files (sort in random order).</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>sorter</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Pluggable sorter as a <a shape="rect"
class="external-link"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Comparator.html"
rel="nofollow"><code>java.util.Comparator<org.apache.camel.component.file.GenericFile></code></a>
class.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>sortBy</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Built-in sort using the <a shape="rect"
href="file-language.html">File Language</a>. Supports nested sorts, so you can
have a sort by file name and as a 2nd group sort by modified date. See sorting
section below for details.</p></td></tr><tr><td colspan="1" row
span="1" class="confluenceTd"><p><code>readLock</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>none</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Used by consumer, to only poll the files if
it has exclusive read-lock on the file e.g., the file is not in-progress or
being written. Camel will wait until the file lock is granted.</p><p>This
option provides the built-in
strategies:</p><ul><li><strong><code>none</code></strong><span> is for no read
locks at all.</span></li><li><strong><code style="line-height: 1.4285715;">
markerFile</code></strong><span style="line-height: 1.4285715;"> Camel creates
a marker file <strong><code>fileName.camelLock</code></strong> and then
holds a lock on it. This option is </span><strong style="line-height:
1.4285715;">not</strong><span style="line-height: 1.4285715;"> available for
the </span><a shape="rect" href="ftp2.html">FTP</a><span style="line-height:
1.4285715;"> component. </span></li><li><stron
g><code>changed</code></strong> is using file length/modification timestamp to
detect whether the file is currently being copied or not. Will at least use 1
sec. to determine this, so this option cannot consume files as fast as the
others, but can be more reliable as the JDK IO API cannot always determine
whether a file is currently being used by another process. The option
<strong><code>readLockCheckInterval</code></strong> can be used to set the
check frequency. This option is <strong>only</strong> avail for the <a
shape="rect" href="ftp2.html">FTP</a> component from <strong>Camel 2.8</strong>
onward. Note: from <strong>Camel 2.10.1</strong> onward the <a shape="rect"
href="ftp2.html">FTP</a> option <strong><code>fastExistsCheck</code></strong>
can be enabled to speedup this <strong><code>readLock</code></strong>
strategy, if the FTP server support the LIST operation with a full file name
(some servers may not).</li><li><strong><code>fileLock</code></strong> is for
using <str
ong><code>java.nio.channels.FileLock</code></strong>. This option is
<strong>not</strong> avail for the <a shape="rect" href="ftp2.html">FTP</a>
component. This approach should be avoided when accessing a remote file system
via a mount/share unless that file system supports distributed file
locks.</li><li><strong><code>rename</code></strong> is for using a try to
rename the file as a test if we can get exclusive
read-lock.</li><li><strong><code style="line-height:
1.4285715;">idempotent</code></strong><span style="line-height: 1.4285715;">
<strong>Camel 2.16</strong> (only file component) is for using a
<strong><code>idempotentRepository</code></strong> as the read-lock. This
allows to use read locks that supports clustering if the idempotent repository
implementation supports that.
</span></li><li><strong><code>idempotent-changed</code></strong><span>
<strong>Camel 2.19</strong> (only file component) is for using a
<strong><code>idempotentRepository</code></strong> and changed as c
ombined read-lock. This allows to use read locks that supports clustering if
the idempotent repository implementation supports that.
</span></li><li><strong><code>idempotent-rename</code></strong><span>
<strong>Camel 2.19</strong> (only file component) is for using a
<strong><code>idempotentRepository</code></strong> and rename as combined
read-lock. This allows to use read locks that supports clustering if the
idempotent repository implementation supports that. </span><span
style="line-height: 1.4285715;"><br
clear="none"></span></li></ul><p><strong>Warning</strong>: most of the read
lock strategies are not suitable for use in clustered mode. That is, you cannot
have multiple consumers attempting to read the same file in the same directory.
In this case, the read locks will not function reliably. The idempotent read
lock supports clustered reliably if you use a cluster aware idempotent
repository implementation such as from <a shape="rect"
href="hazelcast-component.html">Hazelcast
Component</a> or <a shape="rect"
href="infinispan.html">Infinispan</a>.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>readLockTimeout</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>10000</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Optional timeout in
milliseconds for the <strong><code>readLock</code></strong>, if supported. If
the read-lock could not be granted and the timeout triggered, then Camel will
skip the file. At next poll Camel, will try the file again, and this time maybe
the read-lock could be granted. Use a value
of <strong><code>0</code></strong> or lower to indicate forever. In
<strong>Camel 2.0</strong> the default value is
<strong><code>0</code></strong>. Starting with <strong>Camel 2.1</strong> the
default value is <strong><code>10000</code></strong>. Currently
<strong><code>fileLock</code>, </strong><code>changed</code> and
<strong><code>rename</code></strong> support the timeout.</p
><p><strong>Note:</strong> for <a shape="rect" href="ftp2.html">FTP</a> the
>default <strong><code>readLockTimeout</code></strong> value is
><strong><code>20000</code></strong> instead of
><strong><code>10000</code></strong>.
>The <strong><code>readLockTimeout</code></strong> value must be higher
>than <strong><code>readLockCheckInterval</code></strong>, but a rule of thumb
>is to have a timeout that is at least 2 or more times higher than the
><strong><code>readLockCheckInterval</code></strong>. This is needed to ensure
>that ample time is allowed for the read lock process to try to grab the lock
>before the timeout was hit.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>readLockCheckInterval</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p><code>1000</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.6:</strong>
>Interval in milliseconds for the read-lock, if supported by the read lock.
>This interval is used
for sleeping between attempts to acquire the read lock. For example when using
the <code>changed</code> read lock, you can set a higher interval period to
cater for <em>slow writes</em>. The default of 1 sec. may be <em>too fast</em>
if the producer is very slow writing the file. For <a shape="rect"
href="ftp2.html">FTP</a> the default
<strong><code>readLockCheckInterval</code></strong> is
<strong><code>5000</code></strong>.
<span>The <strong><code>readLockTimeout</code></strong> value must be
higher than <strong><code>readLockCheckInterval</code></strong>, but a
rule of thumb is to have a timeout that is at least 2 or more times higher than
the <strong><code>readLockCheckInterval</code></strong>. This is needed to
ensure that ample time is allowed for the read lock process to try to grab the
lock before the timeout was hit.</span></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>readLockMinLength</code></p></td><td
colspan="1" rowspan="1" cl
ass="confluenceTd"><p><code>1</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.10.1:</strong> This option applied only
for <strong><code>readLock=changed</code></strong>. This option allows you to
configure a minimum file length. By default Camel expects the file to contain
data, and thus the default value is <strong>1</strong>. You can set this option
to zero, to allow consuming zero-length files.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>readLockMinAge</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.15</strong>:
This option applies only to <strong><code>readLock=change</code></strong>. This
option allows you to specify a minimum age a file must be before attempting to
acquire the read lock. For example,
use <strong><code>readLockMinAge=300s</code></strong> to require that the
file is at least 5 minutes
old. This can speedup the poll when the file is old enough as it will acquire
the read lock immediately. Notice for FTP: file timestamps reported by FTP
servers are often reported with resolution of minutes,
so <strong><code>readLockMinAge</code></strong> parameter should be
defined in minutes, e.g. <strong>60000</strong> for 1 minute. Notice that Camel
supports specifying this as <strong><code>60s</code></strong>, or
<strong><code>1m</code></strong>, etc.</p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>readLockLoggingLevel</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>WARN</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong>
Logging level used when a read lock could not be acquired. By default
a <strong><code>WARN</code></strong> is logged. You can change this level,
for example to OFF to not have any logging.</p><p>This option is only
applicable for the <strong><code>readLoc
k</code></strong>
types:</p><ul><li><strong><code>changed</code></strong></li><li><strong><code>fileLock</code></strong></li><li><strong><code>rename</code></strong></li></ul></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>readLockMarkerFile</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.14:</strong> Whether to use
marker file with the <strong><code>changed</code>,
<code>rename</code></strong>, or <strong><code>exclusive</code></strong> read
lock types. By default a marker file is used as well to guard against other
processes picking up the same files. This behavior can be turned off by setting
this option to <strong><code>false</code></strong>. For example if you do not
want to write marker files to the file systems by the Camel
application.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>readLockRemoveOnRollback</code>
</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>true</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.16:</strong> This option applied only
for <strong><code>readLock=idempotent</code></strong>. This option allows to
specify whether to remove the file name entry from the idempotent repository
when processing the file failed and a rollback happens. If this option is
false, then the file name entry is confirmed (as if the file did a
commit).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><span>readLockRemoveOnCommit</span></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel
2.16:</strong><span> This option applied only for
<strong><code>readLock=idempotent</code></strong>. This option allows to
specify whether to remove the file name entry from the idempotent repository
when processing the file succeeded and a c
ommit happens. By default the file is not removed which ensures that any
race-condition do not occur so another active node may attempt to grab the
file. Instead the idempotent repository may support eviction strategies that
you can configure to evict the file name entry after X minutes - this ensures
no problems with race conditions.</span></p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>readLockDeleteOrphanLockFiles</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.16:</strong>
Whether or not read lock with marker files should upon startup delete any
orphan read lock files, which may have been left on the file system, if Camel
was not properly shutdown (such as a JVM crash). If turning this option to
false then any orphaned lock file will cause Camel to not attempt to pickup
that file, this could also be due another node is concurrently reading
files from the same shared directory.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>directoryMustExist</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.5:</strong>
Similar to <strong><code>startingDirectoryMustExist</code></strong> but this
applies during polling recursive sub directories.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>doneFileName</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.6:</strong> If provided,
Camel will only consume files if a <em>done</em> file exists. This option
configures what file name to use. Either you can specify a fixed name. Or you
can use dynamic placeholders. The <em>done</em> file is <strong>always</strong>
expected in the same folder as the original file. See <em>
using done file</em> and <em>writing done file</em> sections for
examples.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>exclusiveReadLockStrategy</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Pluggable read-lock as a
<strong><code>org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy</code></strong>
implementation.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>maxMessagesPerPoll</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>An integer to define a maximum messages to
gather per poll. By default no maximum is set. Can be used to set a limit of
e.g. <strong><code>1000</code></strong> to avoid when starting up the
server that there are thousands of files. Set a value
of <strong><code>0</code></strong> or negative
to disable it. See more details at <a shape="rect"
href="batch-consumer.html">Batch Consumer</a>.</p><p><strong>Notice:</strong>
If this option is in use then the <a shape="rect" href="file2.html">File</a>
and <a shape="rect" href="ftp2.html">FTP</a> components will limit
<strong>before</strong> any sorting. For example if you have 100000 files and
use <strong><code>maxMessagesPerPoll=500</code></strong>, then only the first
500 files will be picked up, and then sorted. You can use the
<strong><code>eagerMaxMessagesPerPoll</code></strong> option and set this to
<strong><code>false</code></strong> to allow to scan all files first and then
sort afterwards.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>eagerMaxMessagesPerPoll</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9.3:</strong>
Allows for controlling whether the limit from <strong><code
>maxMessagesPerPoll</code></strong> is eager or not. If eager then the limit
>is during the scanning of files. Where as <code>false</code> would scan all
>files, and then perform sorting. Setting this option to <code>false</code>
>allows for sorting all files first, and then limit the poll. Mind that this
>requires a higher memory usage as all file details are in memory to perform
>the sorting.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>minDepth</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p>0</p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p><strong>Camel 2.8</strong>: The minimum depth to
>start processing when recursively processing a directory. Using
><strong><code>minDepth=1</code></strong> means the base directory. Using
><strong><code>minDepth=2</code></strong> means the first sub
>directory.</p><p>This option is supported by <a shape="rect"
>href="ftp2.html">FTP</a> consumer from <strong>Camel 2.8.2, 2.9</strong>
>onward.</p
></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>maxDepth</code></p></td><td colspan="1"
>rowspan="1"
>class="confluenceTd"><p><code>Integer.MAX_VALUE</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong>
>The maximum depth to traverse when recursively processing a directory. This
>option is supported by <a shape="rect" href="ftp2.html">FTP</a> consumer from
><strong>Camel 2.8.2, 2.9</strong> onward.</p></td></tr><tr><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>processStrategy</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p>A pluggable
><strong><code>org.apache.camel.component.file.GenericFileProcessStrategy</code></strong>
> allowing you to implement your own <strong><code>readLock</code></strong>
>option or similar. Can also be used when special conditions must be met
>before a file can be consumed, such as a special <
em>ready</em> file exists. If this option is set then the
<strong><code>readLock</code></strong> option does not
apply.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>startingDirectoryMustExist</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.5:</strong>
Whether the starting directory must exist. Mind that the
<strong><code>autoCreate</code></strong> option is default enabled, which means
the starting directory is normally auto created if it doesn't exist. You can
disable <strong><code>autoCreate</code></strong> and enable this to ensure the
starting directory must exist. Will thrown an exception if the directory
doesn't exist.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>pollStrategy</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="conf
luenceTd"><p>A pluggable
<strong><code>org.apache.camel.spi.PollingConsumerPollStrategy</code></strong>
allowing you to provide your custom implementation to control error handling
that may occur during the <strong><code>poll</code></strong> operation but
<em>before</em> an <a shape="rect" href="exchange.html">Exchange</a> has been
created and routed by Camel. In other words the error occurred while the
polling was gathering information e.g., access to a file network failed so
Camel cannot access it to scan for files.</p><p>The default implementation will
log the caused exception at <strong><code>WARN</code></strong> level and ignore
it.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>sendEmptyMessageWhenIdle</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9:</strong> If
the polling consumer did not poll any files, you can enable this option to
send an empty message (no body) instead.</p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>consumer.bridgeErrorHandler</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong>
Allows for bridging the consumer to the Camel routing <a shape="rect"
href="error-handler.html">Error Handler</a>, which mean any exceptions occurred
while trying to pickup files, or the likes, will now be processed as a message
and handled by the routing <a shape="rect" href="error-handler.html">Error
Handler</a>. By default the consumer will use the
<strong><code>org.apache.camel.spi.ExceptionHandler</code></strong> to deal
with exceptions, that by default will be logged at
<strong><code>WARN</code></strong>/<strong><code>ERROR</code></strong> level
and ignored. See the following section for more details: <em>How to use the
Camel error handler to deal with exceptions
triggered outside the routing engine</em>.</p></td></tr><tr><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>scheduledExecutorService</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong>
Allows for configuring a custom/shared thread pool to use for the consumer. By
default each consumer has its own single threaded thread pool. This option
allows you to share a thread pool among multiple file
consumers.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>scheduler</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> To use a
custom scheduler to trigger the consumer to run. See more details at <a
shape="rect" href="polling-consumer.html">Polling Consumer</a>, for example
there is a <a shape="rect" href="quartz2.htm
l">Quartz2</a>, and <a shape="rect" href="spring.html">Spring</a> based
scheduler that supports CRON expressions.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>backoffMultiplier</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> To
let the scheduled polling consumer backoff if there has been a number of
subsequent idles/errors in a row. The multiplier is then the number of polls
that will be skipped before the next actual attempt is happening again. When
this option is in use then <strong><code>backoffIdleThreshold</code></strong>
and/or <strong><code>backoffErrorThreshold</code></strong> must also be
configured.</p><p>For more details see: <a shape="rect"
href="polling-consumer.html">Polling Consumer</a>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>backoffIdleThreshold</code></p></td><td
colspan="1" rowsp
an="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> The number of
subsequent idle polls that should happen before the
<strong><code>backoffMultipler</code></strong> should
kick-in.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>backoffErrorThreshold</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong>
The number of subsequent error polls (failed due some error) that should happen
before the <strong><code>backoffMultipler</code></strong> should
kick-in.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>onCompletionExceptionHandler</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.16:</strong> To use a
custom <strong><code>org.apache.camel.spi.
ExceptionHandler</code></strong> to handle any thrown exceptions that happens
during the file on completion process where the consumer does either a commit
or rollback. The default implementation will log any exception
at <strong><code>WARN</code></strong> level and
ignore.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>probeContentType</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.17:</strong> Whether to
enable probing of the content type. If enable then the consumer uses
<code><strong>Files#probeContentType</strong>(<strong>java.nio.file.Path</strong>)</code>
to determine the content-type of the file, and store that as a header with key
<strong><code>Exchange#FILE_CONTENT_TYPE</code></strong> on the
Message.</p><p><strong>Camel 2.15</strong>-<strong>2.16.x</strong> the default
is true.</p></td></tr><tr><td colspan="1" rowspan="1" clas
s="confluenceTd"><p>extendedAttributes</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>null</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.17</strong>: To enable gathering
extended file attributes
through <strong><code>java.nio.file.attribute</code></strong> classes
using <strong><code>Files.getAttribute(ava.nio.file.Path, java.lang.String
attribute)</code></strong>
or <strong><code>Files.readAttributes(ava.nio.file.Path, java.lang.String
attributes)</code></strong> depending on the option value. This option supports
a comma delimited list of attributes to collect e.g.,
<strong><code>basic:creationTime</code></strong>, <strong><code>posix:group</code></strong>
or simple wildcard e.g., <strong><code>posix:*</code></strong>. If the
attribute name is not prefixed, the basic attributes are queried. The result is
stored as a header with
key <strong><code>CamelFileExtendedAttributes</code></strong> and it is of
type
60;<strong><code>Map<String, Object></code></strong> where the key is
the name of the attribute e.g., <strong><code>posix:group</code></strong>
and the value is the attributed returned by the call
to <strong><code>Files.getAttribute()</code></strong> or
<strong><code>Files.readAttributes</code></strong>.</p></td></tr></tbody></table></div></div>
-
-
-<h4 id="File2-Defaultbehaviorforfileconsumer">Default behavior for file
consumer</h4><ul><li><p>By default the file is <strong>not</strong> locked for
the duration of the processing.</p></li><li><p>After the route has completed,
files are moved into the<strong><code> .camel</code></strong> subdirectory, so
that they appear to be deleted.</p></li><li><p>The File Consumer will always
skip any file whose name starts with a dot, such as
<strong><code>.</code></strong>, <strong><code>.camel</code></strong>,
<strong><code>.m2</code></strong> or
<strong><code>.groovy</code>.</strong></p></li><li><p>Only files (not
directories) are matched for valid filename, if options such as:
<strong><code>include</code></strong> or <strong><code>exclude</code></strong>
are used.</p></li></ul><h4 id="File2-Producer">Producer</h4><div
class="confluenceTableSmall"><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Name</p></th><th colspan="
1" rowspan="1" class="confluenceTh"><p>Default Value</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>fileExist</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>Override</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>What to do if a file already
exists with the same name. The following values can be
specified:</p><ul><li><p><strong><code>Override</code></strong> replaces the
existing file.</p></li><li><p><strong><code>Append</code></strong> adds content
to the existing file. </p></li><li><p><strong><code>Fail</code></strong>
throws a <strong><code>GenericFileOperationException</code></strong> indicating
that there is already an existing
file. </p></li><li><p><strong><code>Ignore</code></strong> silently
ignores the problem and <strong>does not</strong> override the existing file,
but assumes everything is okay.</p></li><li><p><strong
><code>Move</code></strong> (<strong>Camel 2.10.1</strong> onward) requires
>that the option <strong><code>moveExisting</code></strong> be configured as
>well. The <strong><code>eagerDeleteTargetFile</code></strong> can be used to
>control what to do if moving the file, and there already exists a file,
>otherwise causing the move operation to fail. The
><strong><code>Move</code></strong> option will move any existing files,
>before writing the target
>file. </p></li><li><p><strong><code>TryRename</code> (Camel
>2.11.1</strong> onward) is only applicable if
><strong><code>tempFileName</code></strong> option is in use. This allows to
>try renaming the file from the temporary name to the actual name, without
>doing any exists check. This check may be faster on some file systems and
>especially FTP servers.</p></li></ul></td></tr><tr><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>tempPrefix</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td>
<td colspan="1" rowspan="1" class="confluenceTd"><p>This option is used to
write the file using a temporary name and then, after the write is complete,
rename it to the real name. Can be used to identify files being written to and
also avoid consumers (not using exclusive read locks) reading in progress
files. Is often used by <a shape="rect" href="ftp2.html">FTP</a> when uploading
big files.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>tempFileName</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.1:</strong> The
<strong>same</strong> as <strong><code>tempPrefix</code></strong> option but
offering a more fine grained control on the naming of the temporary filename as
it uses the <a shape="rect" href="file-language.html">File
Language</a>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>moveExisting</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10.1:</strong>
<a shape="rect" href="expression.html">Expression</a> (such as <a shape="rect"
href="file-language.html">File Language</a>) used to compute file name to use
when <strong><code>fileExist=Move</code></strong> is configured. To move files
into a <strong><code>backup</code></strong> subdirectory just enter
<strong><code>backup</code></strong>.</p><p>This option only supports the
following <a shape="rect" href="file-language.html">File Language</a>
tokens:</p><ul><li><p><strong><code>file:name</code></strong></p></li><li><p><strong><code>file:name.ext</code></strong></p></li><li><p><strong><code>file:name.noext</code></strong></p></li><li><p><strong><code>file:onlyname</code></strong></p></li><li><p><strong><code>file:onlyname.noext</code></strong></p></li><li><p><strong><code>file:ext</code></strong></p></li><li><p><strong><code>fi
le:parent</code></strong></p></li></ul><p><strong>Note</strong>:
the <strong><code>file:parent</code></strong> token is not supported by
the <a shape="rect" href="ftp2.html">FTP</a> component which can only move
files to a directory relative to the <em>current</em>
directory.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>keepLastModified</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.2:</strong> Will keep the
last modified timestamp from the source file (if any). Will use the
<strong><code>Exchange.FILE_LAST_MODIFIED</code></strong> header to located the
timestamp. This header can contain either a
<strong><code>java.util.Date</code></strong> or
<strong><code>long</code></strong> with the timestamp. If the timestamp exists
and the option is enabled it will set this timestamp on the written
file.</p><p><strong>Note:</strong> This option o
nly applies to the <strong>file</strong> producer. It <em>cannot</em> be used
with any of the FTP producers.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>eagerDeleteTargetFile</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.3:</strong>
Whether or not to eagerly delete any existing target file. This option only
applies when you use <strong><code>fileExists=Override</code></strong> and the
<strong><code>tempFileName</code></strong> option as well. You can use this to
disable (set it to <strong><code>false</code></strong>) deleting the
target file before the temp file is written. For example you may write big
files and want the target file to exist while the temp file is being written.
This ensures that the target file is only deleted at the very last moment, just
before the temp file is being renamed to the target filename.</p><p>From <str
ong>Camel 2.10.1</strong> onward this option is also used to control whether
to delete any existing files when <strong><code>fileExist=Move</code></strong>
is enabled, and an existing file exists. If this
option <strong><code>copyAndDeleteOnRenameFail</code></strong> is
<strong><code>false</code></strong>, then an exception will be thrown if an
existing file existed. When <strong><code>true</code></strong> the existing
file is deleted before the move operation.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>doneFileName</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.6:</strong> If
provided, then Camel will write a second file (called <em>done</em>
<em>file</em>) when the original file has been written. The <em>done</em>
<em>file</em> will be empty. This option configures what file name to use. You
can either specify a fixed name, or you c
an use dynamic placeholders. The <em>done</em> <em>file</em> will
<strong>always</strong> be written in the same folder as the original file. See
<em>writing done file</em> section for examples.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>allowNullBody</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.10.1:</strong> Used to
specify if a null body is allowed during file writing. If set to true then an
empty file will be created, when set to false, and attempting to send a null
body to the file component,
a <strong><code>GenericFileWriteException</code></strong> the a message
'Cannot write null body to file' will be
thrown.</p><p>If <strong><code>fileExist=Override</code></strong> the file
will be truncated. If <strong><code>fileExist=append</code></strong> the
file will remain unchanged.</p></td></tr><tr><td colspan="1" rowspan=
"1" class="confluenceTd"><p><code>forceWrites</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.10.5/2.11:</strong> Whether
to force syncing writes to the file system. You can turn this off if you do not
want this level of guarantee, for example if writing to logs / audit logs etc;
this would yield better performance.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>chmod</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.15.0</strong>: Specify the
file p<span style="line-height: 1.4285715;">ermissions which is sent by the
producer</span>, the <span style="line-height: 1.4285715;">chmod value must be
between <strong><code>000</code></strong> and
<strong><code>777</code></strong>; If there is a leading digit like
in <strong><code>0
755</code></strong> we will ignore it.</span></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>chmodDirectory</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.17.0:</strong>
Specify the directory permissions used when the producer creates missing
directories, the chmod value must be
between <strong><code>000</code></strong> and
<strong><code>777</code></strong>; If there is a leading digit like
in <strong><code>0755</code></strong> we will ignore
it.</p></td></tr></tbody></table></div></div>
-
-
-<h4 id="File2-Defaultbehaviorforfileproducer">Default behavior for file
producer</h4><ul><li><p>By default it will override any existing file, if one
exist with the same name.</p></li></ul><h3
id="File2-MoveandDeleteoperations">Move and Delete operations</h3><p>Any move
or delete operations is executed after (post command) the routing has
completed; so during processing of the <strong><code>Exchange</code></strong>
the file is still located in the inbox folder.</p><p>Lets illustrate this with
an example:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("file://inbox?move=.done")
- .to("bean:handleOrder");
-]]></script>
-</div></div><p>When a file is dropped in the
<strong><code>inbox</code></strong> folder, the file consumer notices this and
creates a new <strong><code>FileExchange</code></strong> that is routed to the
<strong><code>handleOrder</code></strong> bean. The bean then processes the
<strong><code>File</code></strong> object. At this point in time the file is
still located in the <strong><code>inbox</code></strong> folder. After the bean
completes, and thus the route is completed, the file consumer will perform the
move operation and move the file to the <strong><code>.done</code></strong>
sub-folder.</p><p>The <strong><code>move</code></strong> and
the <strong><code>preMove</code></strong> options are considered as a
directory name though if you use an expression such as <a shape="rect"
href="file-language.html">File Language</a>, or <a shape="rect"
href="simple.html">Simple</a> then the result of the expression evaluation is
the file name to be used e.g., if you set</p><div class="
code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[move=../backup/copy-of-${file:name}]]></script>
-</div></div><p>then that's using the <a shape="rect"
href="file-language.html">File Language</a> which we use return the file name
to be used), which can be either relative or absolute. If relative, the
directory is created as a sub-folder from within the folder where the file was
consumed.</p><p>By default, Camel will move consumed files to the
<strong><code>.camel</code></strong> sub-folder relative to the directory where
the file was consumed.</p><p>If you want to delete the file after processing,
the route should be:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("file://inobox?delete=true")
- .to("bean:handleOrder");
-]]></script>
-</div></div><p>We have introduced a <strong>pre</strong> move operation to
move files <strong>before</strong> they are processed. This allows you to mark
which files have been scanned as they are moved to this sub folder before being
processed.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("file://inbox?preMove=inprogress")
- .to("bean:handleOrder");
-]]></script>
-</div></div><p>You can combine the <strong>pre</strong> move and the regular
move:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("file://inbox?preMove=inprogress&move=.done")
- .to("bean:handleOrder");
-]]></script>
-</div></div><p>So in this situation, the file is in the
<strong><code>inprogress</code></strong> folder when being processed and after
it's processed, it's moved to the <strong><code>.done</code></strong>
folder.</p><h4 id="File2-FineGrainedControlUsingThemoveandpreMoveOptions">Fine
Grained Control Using The <code>move</code> and <code>preMove</code>
Options</h4><p>The <strong>move</strong> and <strong>preMove</strong> options
are <a shape="rect" href="expression.html">Expression</a>-based, so we
have the full power of the <a shape="rect" href="file-language.html">File
Language</a> to do advanced configuration of the directory and name pattern.<br
clear="none"> Camel will, in fact, internally convert the directory name you
enter into a <a shape="rect" href="file-language.html">File Language</a>
expression. So when we enter <strong><code>move=.done</code></strong> Camel
will convert this into:
<strong><code>${</code><code>file:parent</code><code>}/.done/${</code><code>file:
onlyname</code>}</strong>. This is only done if Camel detects that you have
not provided a <strong><code>$</code>{}</strong> in the option value
yourself. So when you enter a <strong><code>$</code>{}</strong> Camel will
<strong>not</strong> convert it and thus you have the full power.</p><p>So if
we want to move the file into a backup folder with today's date as the pattern,
we can do:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[move=backup/${date:now:yyyyMMdd}/${file:name}
-]]></script>
-</div></div><h4 id="File2-AboutmoveFailed">About
<strong><code>moveFailed</code></strong></h4><p>The
<strong><code>moveFailed</code></strong> option allows you to move files that
<strong>could not</strong> be processed successfully to another location such
as a error folder of your choice. For example to move the files in an error
folder with a timestamp you can use
<strong><code>moveFailed=/error/${</code><code>file:name.noext</code><code>}-${date:now:yyyyMMddHHmmssSSS}.${</code><code>file:ext</code>}</strong>.</p><p>See
more examples at <a shape="rect" href="file-language.html">File
Language</a></p><h3 id="File2-MessageHeaders">Message Headers</h3><p>The
following headers are supported by this component:</p><h4
id="File2-Fileproduceronly">File producer only</h4><div
class="confluenceTableSmall"><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Header</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Desc
ription</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelFileName</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Specifies the name of the file to write
(relative to the endpoint directory). This name can be a <code>String</code>; a
<code>String</code> with a <a shape="rect" href="file-language.html">File
Language</a> or <a shape="rect" href="simple.html">Simple</a> expression; or an
<a shape="rect" href="expression.html">Expression</a> object. If it's
<strong><code>null</code></strong> then Camel will auto-generate a filename
based on the message unique ID.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelFileNameProduced</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The absolute file path (path +
name) for the output file that was written. This header is set by Camel and its
purpose is providing end-users with the name of the file that was
written.</p></td></tr><tr><td colspan="1
" rowspan="1"
class="confluenceTd"><p><code>CamelOverruleFileName</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.11:</strong> Is
used for overruling <code>CamelFileName</code> header and use the value instead
(but only once, as the producer will remove this header after writing the
file). The value can be only be a String. Notice that if the option
<strong><code>fileName</code></strong> has been configured, then this is still
being evaluated.</p></td></tr></tbody></table></div></div>
-
-
-<h4 id="File2-Fileconsumeronly">File consumer only</h4><div
class="confluenceTableSmall"><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Header</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>CamelFileName</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Name of the consumed file as a
relative file path with offset from the starting directory configured on the
endpoint.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelFileNameOnly</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Only the file name (the name with no
leading paths).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelFileAbsolute</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>A <code>boolean</code> option specifying
whether the consumed fi
le denotes an absolute path or not. Should normally be <code>false</code> for
relative paths. Absolute paths should normally not be used but we added to the
move option to allow moving files to absolute paths. But can be used elsewhere
as well.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelFileAbsolutePath</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The absolute path to the file.
For relative files this path holds the relative path
instead.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelFilePath</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The file path. For relative files this is
the starting directory + the relative filename. For absolute files this is the
absolute path.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelFileRelativePath</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>The relative
path.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelFileParent</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The parent path.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelFileLength</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>A <code>long</code> value containing the
file size.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelFileLastModified</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>A <code>Long</code> value
containing the last modified timestamp of the file. In <strong>Camel 2.10.3 and
older</strong> the type is
<code>Date</code>.</p></td></tr></tbody></table></div></div>
-
-
-<h3 id="File2-BatchConsumer">Batch Consumer</h3><p>This component implements
the <a shape="rect" href="batch-consumer.html">Batch Consumer</a>.</p><h4
id="File2-ExchangeProperties,fileconsumeronly">Exchange Properties, file
consumer only</h4><p>As the file consumer implements
the <strong><code>BatchConsumer</code></strong> it supports batching the
files it polls. By batching we mean that Camel will add the following
additional properties to the <a shape="rect" href="exchange.html">Exchange</a>,
so you know the number of files polled, the current index, and whether the
batch is already completed.</p><div class="confluenceTableSmall"><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Property</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>CamelBatchSize</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"
><p>The total number of files that was polled in this
>batch.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>CamelBatchIndex</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p>The current index of the batch. Starts
>from 0.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>CamelBatchComplete</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p>A <code>boolean</code> value
>indicating the last <a shape="rect" href="exchange.html">Exchange</a> in the
>batch. Is only <code>true</code> for the last
>entry.</p></td></tr></tbody></table></div></div>
-
-
-<p>This allows you for instance to know how many files exist in this batch and
for instance let the <a shape="rect" href="aggregator2.html">Aggregator2</a>
aggregate this number of files.</p><h3
id="File2-Usingcharset">Using <code>charset</code></h3><p><strong>Available
as of Camel 2.9.3</strong><br clear="none">
The <strong><code>charset</code></strong> option allows for configuring an
encoding of the files on both the consumer and producer endpoints. For example
if you read utf-8 files, and want to convert the files to iso-8859-1, you can
do:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("file:inbox?charset=utf-8")
- .to("file:outbox?charset=iso-8859-1")
-]]></script>
-</div></div><p>You can also use the
<strong><code>convertBodyTo</code></strong> in the route. In the example below
we have still input files in utf-8 format, but we want to convert the file
content to a byte array in iso-8859-1 format. And then let a bean process the
data. Before writing the content to the outbox folder using the current
charset.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("file:inbox?charset=utf-8")
- .convertBodyTo(byte[].class, "iso-8859-1")
- .to("bean:myBean")
- .to("file:outbox");
-]]></script>
-</div></div><p>If you omit the charset on the consumer endpoint, then Camel
does not know the charset of the file, and would by default use "UTF-8".
However you can configure a JVM system property to override and use a different
default encoding with the key
<strong><code>org.apache.camel.default.charset</code></strong>.</p><p>In the
example below this could be a problem if the files is not in UTF-8 encoding,
which would be the default encoding for read the files.<br clear="none"> In
this example when writing the files, the content has already been converted to
a byte array, and thus would write the content directly as is (without any
further encodings).</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("file:inbox")
- .convertBodyTo(byte[].class, "iso-8859-1")
- .to("bean:myBean")
- .to("file:outbox");
-]]></script>
-</div></div><p>You can also override and control the encoding dynamic when
writing files, by setting a property on the exchange with the key
<strong><code>Exchange.CHARSET_NAME</code></strong>. For example in the route
below we set the property with a value from a message header.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("file:inbox")
- .convertBodyTo(byte[].class, "iso-8859-1")
- .to("bean:myBean")
- .setProperty(Exchange.CHARSET_NAME, header("someCharsetHeader"))
- .to("file:outbox");
-]]></script>
-</div></div><p>We suggest to keep things simpler, so if you pickup files with
the same encoding, and want to write the files in a specific encoding, then
favor to use the <strong><code>charset</code></strong> option on the
endpoints.</p><p>Notice that if you have explicit configured a
<strong><code>charset</code></strong> option on the endpoint, then that
configuration is used, regardless of the
<strong><code>Exchange.CHARSET_NAME</code></strong> property.</p><p>If you have
some issues then you can enable <strong><code>DEBUG</code></strong>
logging on <strong><code>org.apache.camel.component.file</code></strong>, and
Camel logs when it reads/write a file using a specific charset.<br
clear="none"> For example the route below will log the following:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("file:inbox?charset=utf-8")
- .to("file:outbox?charset=iso-8859-1")
-]]></script>
-</div></div><p>And the logs:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[DEBUG GenericFileConverter - Read
file /Users/davsclaus/workspace/camel/camel-core/target/charset/input/input.txt
with charset utf-8
+<div class="wiki-content maincontent"><h2 id="File2-FileComponent">File
Component</h2><p>The File component provides access to file systems, allowing
files to be processed by any other Camel <a shape="rect"
href="components.html">Components</a> or messages from other components to be
saved to disk.</p><h3 id="File2-URIformat">URI
format</h3><plain-text-body>file:directoryName[?options]
+</plain-text-body><p>or</p><plain-text-body>file://directoryName[?options]
[... 538 lines stripped ...]