Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.2.6. File filtering
Overview Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
When a poller endpoint is configured to poll a directory it will attempt to consume any file placed into that directory. If you want to limit the files a poller endpoint will attempt to consume, you can configure the endpoint to filter files based on their names. To do so, you must supply the endpoint with an implementation of the
java.io.FileFilter interface.
There are several file filter implementation available in open source including the Apache Commons IO implementations and the Apache Jakarta-ORO implementations. You can also implement your own file filter if you need specific filtering capabilities.
Implementing a file filter Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To implement a file filter, you need to provide an implementation of the
java.io.FileFilter interface. The FileFilter interface has a single method, accept(), that needs to be implemented. Example 2.11, “File filter's accept method” shows the signature of the accept() method.
Example 2.11. File filter's accept method
public boolean accept()(java.io.File pathname);
The
accept() method takes a File object that represents the file being checked against the filter. If the file passes the filter, the accept() method should return true. If the file does not pass, then the method should return false.
Example 2.12, “Simple file filter implementation” shows a file filter implementation that matches against a string passed into its constructor.
Example 2.12. Simple file filter implementation
Configuring an endpoint to use a file filter Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
You configure a poller endpoint to use a file filter using its
filter attribute. The filter attribute's value is a reference to a bean element specifying the class of the file filter implementation.
Example 2.13, “Poller endpoint using a file filter” shows configuration for a poller endpoint that uses the file filter implemented in Example 2.11, “File filter's accept method”. The
constructor-arg element sets the filter's fitlername by passing a value into the constructor.
Example 2.13. Poller endpoint using a file filter
Note
You can also configure a poller endpoint to use a file filter by adding a child
filter element to the endpoint's configuration. The filter element simply wraps the bean element that configures the file filter.