ave4496
ave4496

Reputation: 3018

Skip copying of file if target is the same

I am trying to build an auto sync application. The files should just be copied if e.g. the content has changed. Since I am new to camel and I didn't find anything I would like to know if it is possible to somehow compare the target file with the source file (if there is one).

public class App {

    public static void main(String[] args) {
        final long durationMs = 2000;
        final CamelContext camelContext = new DefaultCamelContext();
        try {
            camelContext.addRoutes(new RouteBuilder() {
                @Override
                public void configure() throws Exception {
                    from("file:/home/av/Schreibtisch/src?noop=true&recursive=true&maxDepth=100")
                            .to("file:/home/av/Schreibtisch/target");
                }
            });
            camelContext.start();
            Thread.sleep(durationMs);
            camelContext.stop();

        } catch (Exception camelException) {
            camelException.printStackTrace();
        }
    }

}

Upvotes: 0

Views: 46

Answers (1)

Hassam Abdelillah
Hassam Abdelillah

Reputation: 2294

There is a whole section in Apache Camel documentation to see how to avoid consuming a certain file under certain condtions. idempotent and idempotentKey are the solution here.

Maybe your discriminatory conditions to tell if the file is already consumed would be :

  1. File size (${file:name}-${file:size})
  2. File timestamp (${file:name}-${file:modified})
  3. Implement a more complex conditions.

For example, to use the size of the file. It would be something along the lines of:

from("file:/somedir?noop=true&idempotentKey=${file:name}-${file:size}")

Upvotes: 2

Related Questions