org.apache.commons.io.monitor.FileAlterationListenerAdaptor Java Examples

The following examples show how to use org.apache.commons.io.monitor.FileAlterationListenerAdaptor. 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: FileMonitor.java    From MercuryTrade with MIT License 6 votes vote down vote up
public void start() {
    String gamePath = Configuration.get().applicationConfiguration().get().getGamePath();

    File folder = new File(gamePath + "logs");
    this.fileHandler = new MessageFileHandler(gamePath + "logs/Client.txt");
    FileAlterationObserver observer = new FileAlterationObserver(folder);
    monitor = new FileAlterationMonitor(POLLING_INTERVAL);
    FileAlterationListener listener = new FileAlterationListenerAdaptor() {
        @Override
        public void onFileChange(File file) {
            fileHandler.parse();
        }
    };

    observer.addListener(listener);
    monitor.addObserver(observer);
    try {
        monitor.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #2
Source File: TorrentFileWatcherTest.java    From joal with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldBuild() {
    try {
        final TorrentFileWatcher watcher = new TorrentFileWatcher(new FileAlterationListenerAdaptor(), torrentsPath);
        watcher.start();
        watcher.stop();
    } catch (final Throwable e) {
        fail("Should Not fail");
    }
}
 
Example #3
Source File: TorrentFileWatcherTest.java    From joal with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFaiToStartWithNonExistingPath() throws IOException {
    final Path directory = Files.createDirectory(torrentsPath.resolve("sub-folder"));
    final TorrentFileWatcher torrentFileWatcher = new TorrentFileWatcher(
            new FileAlterationListenerAdaptor(),
            directory,
            10
    );

    Files.delete(directory);

    assertThatThrownBy(torrentFileWatcher::start)
            .isInstanceOf(IllegalStateException.class);
}
 
Example #4
Source File: TorrentFileWatcherTest.java    From joal with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldNotBuildWithNullMonitoredFolder() {
    assertThatThrownBy(() -> new TorrentFileWatcher(new FileAlterationListenerAdaptor(), null))
            .isInstanceOf(NullPointerException.class)
            .hasMessageContaining("monitoredFolder cannot be null");
}
 
Example #5
Source File: TorrentFileWatcherTest.java    From joal with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldNotBuildWithNonExistingMonitoredFolder() {
    assertThatThrownBy(() -> new TorrentFileWatcher(new FileAlterationListenerAdaptor(), torrentsPath.resolve("nop")))
            .isInstanceOf(IllegalArgumentException.class)
            .hasMessageContaining("Folder '" + torrentsPath.resolve("nop").toAbsolutePath() + "' does not exists.");
}
 
Example #6
Source File: TorrentFileWatcherTest.java    From joal with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldNotBuildWithNullInterval() {
    assertThatThrownBy(() -> new TorrentFileWatcher(new FileAlterationListenerAdaptor(), torrentsPath, null))
            .isInstanceOf(NullPointerException.class)
            .hasMessageContaining("interval cannot be null");
}
 
Example #7
Source File: TorrentFileWatcherTest.java    From joal with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldNotBuildWithIntervalLessThan1() {
    assertThatThrownBy(() -> new TorrentFileWatcher(new FileAlterationListenerAdaptor(), torrentsPath, 0))
            .isInstanceOf(IllegalArgumentException.class)
            .hasMessageContaining("interval cannot be less than 1");
}