当前位置: 首页>>代码示例>>Java>>正文


Java FileAlterationListenerAdaptor类代码示例

本文整理汇总了Java中org.apache.commons.io.monitor.FileAlterationListenerAdaptor的典型用法代码示例。如果您正苦于以下问题:Java FileAlterationListenerAdaptor类的具体用法?Java FileAlterationListenerAdaptor怎么用?Java FileAlterationListenerAdaptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileAlterationListenerAdaptor类属于org.apache.commons.io.monitor包,在下文中一共展示了FileAlterationListenerAdaptor类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerFileListener

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; //导入依赖的package包/类
/**
 * Creates and registers a file listener with the help of the specified build command.
 * 
 * @param command The build command.
 * 
 * @throws Exception If any exception occurs.
 */

private final void registerFileListener(final BuildCommand command) throws Exception {
	final DocsProject project = command.getProject();
	
	final FileAlterationObserver observer = new FileAlterationObserver(project.getDirectory());
	observer.addListener(new FileAlterationListenerAdaptor() {
		
		@Override
		public final void onDirectoryChange(final File directory) {
			rebuildIfNeeded(command, directory);
		}
		
		@Override
		public final void onFileChange(final File file) {
			rebuildIfNeeded(command, file);
		}
		
	});
	monitor.addObserver(observer);
	monitor.start();
}
 
开发者ID:Skyost,项目名称:SkyDocs,代码行数:29,代码来源:ServeCommand.java

示例2: start

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; //导入依赖的package包/类
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();
    }
}
 
开发者ID:Exslims,项目名称:MercuryTrade,代码行数:23,代码来源:FileMonitor.java

示例3: shouldBuild

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; //导入依赖的package包/类
@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");
    }
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:11,代码来源:TorrentFileWatcherTest.java

示例4: observeConfigChanges

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; //导入依赖的package包/类
private void observeConfigChanges() throws Exception
{
    if (watchConfigInterval < 0)
    {
        return;
    }

    FileAlterationListenerAdaptor listener = new FileAlterationListenerAdaptor()
    {
        @Override
        public void onFileChange(File file)
        {
            LOG.info("Config file changed: {}", configPath);
            try
            {
                readConfig(true);
            }
            catch (ConfigException e)
            {
                exitWithError("Failed to refresh config: " + e.getMessage(), false);
                return;
            }
        }
    };

    String filename = configPath.substring(configPath.lastIndexOf('/') + 1);
    String directory = configPath.substring(0, configPath.lastIndexOf('/'));

    FileAlterationObserver observer = new FileAlterationObserver(
            new File(directory),
            FileFilterUtils.nameFileFilter(filename)
    );
    observer.addListener(listener);

    FileAlterationMonitor monitor = new FileAlterationMonitor(watchConfigInterval);
    monitor.addObserver(observer);

    monitor.start();
}
 
开发者ID:ustream,项目名称:yolo,代码行数:40,代码来源:Yolo.java

示例5: shouldNotBuildWithNullMonitoredFolder

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; //导入依赖的package包/类
@Test
public void shouldNotBuildWithNullMonitoredFolder() {
    assertThatThrownBy(() -> new TorrentFileWatcher(new FileAlterationListenerAdaptor(), null))
            .isInstanceOf(NullPointerException.class)
            .hasMessageContaining("monitoredFolder cannot be null");
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:7,代码来源:TorrentFileWatcherTest.java

示例6: shouldNotBuildWithNonExistingMonitoredFolder

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; //导入依赖的package包/类
@Test
public void shouldNotBuildWithNonExistingMonitoredFolder() {
    assertThatThrownBy(() -> new TorrentFileWatcher(new FileAlterationListenerAdaptor(), torrentsPath.resolve("nop")))
            .isInstanceOf(IllegalArgumentException.class)
            .hasMessageContaining("Folder '" + torrentsPath.resolve("nop").toAbsolutePath() + "' does not exists.");
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:7,代码来源:TorrentFileWatcherTest.java

示例7: shouldNotBuildWithNullInterval

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; //导入依赖的package包/类
@Test
public void shouldNotBuildWithNullInterval() {
    assertThatThrownBy(() -> new TorrentFileWatcher(new FileAlterationListenerAdaptor(), torrentsPath, null))
            .isInstanceOf(NullPointerException.class)
            .hasMessageContaining("interval cannot be null");
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:7,代码来源:TorrentFileWatcherTest.java

示例8: shouldNotBuildWithIntervalLessThan1

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; //导入依赖的package包/类
@Test
public void shouldNotBuildWithIntervalLessThan1() {
    assertThatThrownBy(() -> new TorrentFileWatcher(new FileAlterationListenerAdaptor(), torrentsPath, 0))
            .isInstanceOf(IllegalArgumentException.class)
            .hasMessageContaining("interval cannot be less than 1");
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:7,代码来源:TorrentFileWatcherTest.java

示例9: start

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; //导入依赖的package包/类
/**
 * コピー元ディレクトリの監視を開始します。
 * コピー元ディレクトリ内のファイルが更新されたら、そのファイルをコピー先ディレクトリにコピーします。
 *
 * @param srcDir コピー元ディレクトリ
 * @param dstDir コピー先ディレクトリ
 * @return 0 (正常終了)
 * @thrrows Exception
 */
public int start(final String srcDir, final String dstDir) throws Exception {
	FileAlterationObserver observer = new FileAlterationObserver(srcDir);
	int interval = NumberUtils.toInt(System.getProperty(MONITOR_INTERVAL), 1000);
	final FileAlterationMonitor monitor
			= new FileAlterationMonitor(interval);

	FileAlterationListener listener = new FileAlterationListenerAdaptor() {
		@Override
		public void onFileChange(File file) {
			if (!file.isFile()) {
				return;
			}
			String relativePath = StringUtils.substringAfter(file.getAbsolutePath(), srcDir);
			File dstFile = new File(dstDir, relativePath);
			LOG.info("コピーします {} -> {}", file.getAbsolutePath(), dstFile.getAbsolutePath());
			try {
				FileUtils.copyFile(file, dstFile);
			} catch (IOException e) {
				LOG.error("ファイルコピーに失敗 ", e);
			}
		}
	};

	observer.addListener(listener);
	monitor.addObserver(observer);
	monitor.start();

	// TODO ファイル監視方式の統一
	String continuFilePath = System.getProperty("cc.cgfile", ".cg");
	ControlFile continueFile = new ControlFile(continuFilePath, new ControlFile.Listener() {
		@Override
		public void onDelete() throws Exception {
			monitor.stop();
		}
	});
	continueFile.watch();

	while(continueFile.exists()) {
		// 制御ファイルが存在し続ける間、処理を継続
	}

	return 0;
}
 
开发者ID:sitoolkit,项目名称:sit-ad,代码行数:53,代码来源:ContinuousCopy.java


注:本文中的org.apache.commons.io.monitor.FileAlterationListenerAdaptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。