Java Code Examples for org.apache.commons.io.monitor.FileAlterationObserver#checkAndNotify()

The following examples show how to use org.apache.commons.io.monitor.FileAlterationObserver#checkAndNotify() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirectoryMonitor.java    From fuchsia with Apache License 2.0 6 votes vote down vote up
public DirectoryMonitor(String directorypath, long polling, String classname) {

        this.directory = new File(directorypath);
        this.trackedClassName = classname;
        this.polling = polling;

        if (!directory.isDirectory()) {
            LOG.info("Monitored directory {} not existing - creating directory", directory.getAbsolutePath());
            if (!this.directory.mkdirs()) {
                throw new IllegalStateException("Monitored directory doesn't exist and cannot be created.");
            }
        }

        // We observes all files.
        FileAlterationObserver observer = new FileAlterationObserver(directory, TrueFileFilter.INSTANCE);
        observer.checkAndNotify();
        observer.addListener(new FileMonitor());
        monitor = new FileAlterationMonitor(polling, observer);

    }
 
Example 2
Source File: DefaultClassSource.java    From util4j with Apache License 2.0 5 votes vote down vote up
private void checkFileChange()
{
	for (int i=0;i<observers.size();i++) {
		 FileAlterationObserver observer =observers.get(i);
		 observer.checkAndNotify();
     }
}
 
Example 3
Source File: ObserverFactoryTest.java    From bonita-ui-designer with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_create_an_observer_that_notify_when_a_file_is_created() throws Exception {

    FileAlterationObserver observer = factory.create(monitoredFolder, listener);
    Path aFile = Files.write(monitoredFolder.resolve("aFile"), "coucou".getBytes());
    observer.checkAndNotify();

    assertThat(listener.getChanged()).containsExactly(aFile);
}
 
Example 4
Source File: ObserverFactoryTest.java    From bonita-ui-designer with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void should_create_an_observer_that_notify_when_a_file_is_modified() throws Exception {
    Files.write(monitoredFolder.resolve("aFile"), "coucou".getBytes());

    FileAlterationObserver observer = factory.create(monitoredFolder, listener);
    Files.write(monitoredFolder.resolve("aFile"), "modified content".getBytes());
    observer.checkAndNotify();

    assertThat(listener.getChanged()).containsExactly(monitoredFolder.resolve("aFile"));
}