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


Java FileAlterationListener类代码示例

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


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

示例1: addFileAlterationObserver

import org.apache.commons.io.monitor.FileAlterationListener; //导入依赖的package包/类
/**
 * Add {@link org.apache.commons.io.monitor.FileAlterationMonitor}s for the given
 * root directory and any nested subdirectories under the root directory to the given
 * {@link org.apache.commons.io.monitor.FileAlterationMonitor}.
 *
 * @param monitor a {@link org.apache.commons.io.monitor.FileAlterationMonitor}
 * @param listener a {@link org.apache.commons.io.monitor.FileAlterationListener}
 * @param rootDir root directory
 */
public static void addFileAlterationObserver(FileAlterationMonitor monitor, FileAlterationListener listener,
    File rootDir) {
  // Add a observer for the current root directory
  FileAlterationObserver observer = new FileAlterationObserver(rootDir);
  observer.addListener(listener);
  monitor.addObserver(observer);

  // List subdirectories under the current root directory
  File[] subDirs = rootDir.listFiles(new FileFilter() {
    @Override
    public boolean accept(File file) {
      return file.isDirectory();
    }
  });

  if (subDirs == null || subDirs.length == 0) {
    return;
  }

  // Recursively add a observer for each subdirectory
  for (File subDir : subDirs) {
    addFileAlterationObserver(monitor, listener, subDir);
  }
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:34,代码来源:SchedulerUtils.java

示例2: start

import org.apache.commons.io.monitor.FileAlterationListener; //导入依赖的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: addMonitor

import org.apache.commons.io.monitor.FileAlterationListener; //导入依赖的package包/类
/**
 * 增加监视器
 *
 * @param path     监听的文件夹路径
 * @param listener 事件回调接口
 * @return 监听器的id
 * @throws JNotifyException {@link JNotifyException}
 */
public static int addMonitor(String path, FileAlterationListener listener) throws JNotifyException {
    File file = new File(path);
    FileAlterationObserver observer = new FileAlterationObserver(file);
    observer.checkAndNotify();
    observer.addListener(listener);
    int mask = JNotify.FILE_CREATED | JNotify.FILE_DELETED
            | JNotify.FILE_MODIFIED;
    return JNotify.addWatch(path, mask, false, new FileEventListener(observer));
}
 
开发者ID:baidu,项目名称:openrasp,代码行数:18,代码来源:FileScanMonitor.java

示例4: TorrentFileWatcher

import org.apache.commons.io.monitor.FileAlterationListener; //导入依赖的package包/类
TorrentFileWatcher(final FileAlterationListener listener, final Path monitoredFolder, final Integer interval) {
    Preconditions.checkNotNull(listener, "listener cannot be null");
    Preconditions.checkNotNull(monitoredFolder, "monitoredFolder cannot be null");
    Preconditions.checkArgument(Files.exists(monitoredFolder), "Folder '" + monitoredFolder.toAbsolutePath() + "' does not exists.");
    Preconditions.checkNotNull(interval, "interval cannot be null");
    Preconditions.checkArgument(interval > 0, "interval cannot be less than 1");
    this.listener = listener;
    this.monitoredFolder = monitoredFolder.toFile();
    this.monitor = new FileAlterationMonitor(interval);
    this.observer = new FileAlterationObserver(this.monitoredFolder, TORRENT_FILE_FILTER);

    this.observer.addListener(this.listener);
    monitor.addObserver(this.observer);
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:15,代码来源:TorrentFileWatcher.java

示例5: monitorCollection

import org.apache.commons.io.monitor.FileAlterationListener; //导入依赖的package包/类
/**

@method monitorCollection
*/
   private FileAlterationMonitor monitorCollection (String collection) throws Exception {
   	// prtln ("monitorCollection() - " + collection);
   	
   	AssetCollection assetCollection = this.getCollection(collection);
   	
       if (assetCollection == null) {
           // Test to see if monitored folder exists
           throw new RuntimeException("AssetCollection not found: " + collection);
       }
       
       File folder = assetCollection.getDirectory();
       if (!folder.exists())
       	throw new RuntimeException("Folder not found at: " + folder);

       FileAlterationObserver observer = new FileAlterationObserver(folder);
       FileAlterationMonitor monitor =
               new FileAlterationMonitor(pollingInterval);
               
	FileAlterationListener listener = new AssetFileListener(collection, this);

       observer.addListener(listener);
       monitor.addObserver(observer);
       monitor.start();
       // prtln (" .. monitoring " + collection);
       return monitor;
   }
 
开发者ID:NCAR,项目名称:dls-repository-stack,代码行数:31,代码来源:AssetFileManager.java

示例6: getFileObserverListeners

import org.apache.commons.io.monitor.FileAlterationListener; //导入依赖的package包/类
public List<FileObserverListener> getFileObserverListeners() {
	List<FileObserverListener> listeners = new ArrayList<FileObserverListener>();

	// TODO check if this interface casting is allowed
	for (FileAlterationListener listener : observer.getListeners()) {
		listeners.add((FileObserverListener) listener);
	}
	return listeners;
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:10,代码来源:FileObserver.java

示例7: registerDirectoryListener

import org.apache.commons.io.monitor.FileAlterationListener; //导入依赖的package包/类
@Override
@SuppressWarnings("PMD.EmptyCatchBlock")
public synchronized void registerDirectoryListener(File directory, DirectoryListener directoryListener) {
    FileAlterationObserver newObserver = new FileAlterationObserver(directory);
    FileAlterationObserver oldObserver = directoryObservers.putIfAbsent(directory, newObserver);
    final FileAlterationObserver observer;
    if (oldObserver == null) {
        observer = newObserver;
    } else {
        observer = oldObserver;
    }
    SFMF4JFileAlterationListener newListener = new SFMF4JFileAlterationListener(directoryListener);
    boolean found = false;
    for (FileAlterationListener fal : observer.getListeners()) {
        if (newListener.equals(fal)) {
            found = true;
            break;
        }
    }
    if (!found) {
        observer.addListener(newListener);
    }
    if (observer == newObserver) {
        try {
            observer.initialize();
            fileMonitor.addObserver(observer);
        } catch (Exception ex) {
            //trap
        }
    }

}
 
开发者ID:sworisbreathing,项目名称:sfmf4j,代码行数:33,代码来源:CommonsIOFileMonitorServiceImpl.java

示例8: start

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