本文整理汇总了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();
}
示例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();
}
}
示例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");
}
}
示例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();
}
示例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");
}
示例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.");
}
示例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");
}
示例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");
}
示例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;
}