本文整理汇总了Java中org.apache.commons.vfs2.impl.DefaultFileMonitor.addFile方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultFileMonitor.addFile方法的具体用法?Java DefaultFileMonitor.addFile怎么用?Java DefaultFileMonitor.addFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.vfs2.impl.DefaultFileMonitor
的用法示例。
在下文中一共展示了DefaultFileMonitor.addFile方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFileModified
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
public void testFileModified() throws Exception
{
writeToFile(testFile);
FileObject fileObj = fsManager.resolveFile(testFile.toURL().toString());
DefaultFileMonitor monitor = new DefaultFileMonitor(new TestFileListener());
monitor.setDelay(100);
monitor.addFile(fileObj);
monitor.start();
// Need a long delay to insure the new timestamp doesn't truncate to be the same as
// the current timestammp. Java only guarantees the timestamp will be to 1 second.
Thread.sleep(1000);
long value = System.currentTimeMillis();
boolean rc = testFile.setLastModified(value);
assertTrue("setLastModified succeeded",rc);
Thread.sleep(300);
assertTrue("No event occurred", changeStatus != 0);
assertTrue("Incorrect event", changeStatus == 1);
monitor.stop();
}
示例2: testFileRecreated
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
public void testFileRecreated() throws Exception
{
FileObject fileObj = fsManager.resolveFile(testFile.toURL().toString());
DefaultFileMonitor monitor = new DefaultFileMonitor(new TestFileListener());
monitor.setDelay(100);
monitor.addFile(fileObj);
monitor.start();
writeToFile(testFile);
Thread.sleep(300);
assertTrue("No event occurred", changeStatus != 0);
assertTrue("Incorrect event " + changeStatus, changeStatus == 3);
changeStatus = 0;
testFile.delete();
Thread.sleep(300);
assertTrue("No event occurred", changeStatus != 0);
assertTrue("Incorrect event " + changeStatus, changeStatus == 2);
changeStatus = 0;
Thread.sleep(500);
monitor.addFile(fileObj);
writeToFile(testFile);
Thread.sleep(300);
assertTrue("No event occurred", changeStatus != 0);
assertTrue("Incorrect event " + changeStatus, changeStatus == 3);
monitor.stop();
}
示例3: start
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
/**
* Starts watching the file system for changes to trigger a bake.
*
* @param res Commandline options
* @param config Configuration settings
*/
public void start(final LaunchOptions res, CompositeConfiguration config) {
try {
FileSystemManager fsMan = VFS.getManager();
FileObject listenPath = fsMan.resolveFile(res.getSource(), config.getString( ConfigUtil.Keys.CONTENT_FOLDER));
FileObject templateListenPath = fsMan.resolveFile(res.getSource(), config.getString( ConfigUtil.Keys.TEMPLATE_FOLDER));
FileObject assetPath = fsMan.resolveFile(res.getSource(), config.getString( ConfigUtil.Keys.ASSET_FOLDER));
System.out.println("Watching for (content, template, asset) changes in [" + res.getSource() + "]");
DefaultFileMonitor monitor = new DefaultFileMonitor(new CustomFSChangeListener(res, config));
monitor.setRecursive(true);
monitor.addFile(listenPath);
monitor.addFile(templateListenPath);
monitor.addFile(assetPath);
monitor.start();
} catch (FileSystemException e) {
e.printStackTrace();
}
}
示例4: watchDir
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
@Override
public void watchDir(File file) throws IOException {
FileSystemManager fileSystemManager = VFS.getManager();
FileObject dirToWatchFO = null;
dirToWatchFO = fileSystemManager.resolveFile(file.getAbsolutePath());
//IFileListenerService fileListener = this.beanService.getBean(ApacheDefaultFileListener.class);
DefaultFileMonitor fileMonitor = this.beanService.getBean(DefaultFileMonitor.class);
fileMonitor.setRecursive(true);
fileMonitor.addFile(dirToWatchFO);
fileMonitor.start();
this.fileMonitors.add(fileMonitor);
}
示例5: start
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
/**
* Starts watching the file system for changes to trigger a bake.
*
* @param res Commandline options
* @param config Configuration settings
*/
public void start(final LaunchOptions res, CompositeConfiguration config) {
try {
FileSystemManager fsMan = VFS.getManager();
FileObject listenPath = fsMan.resolveFile(res.getSource(), config.getString( ConfigUtil.Keys.CONTENT_FOLDER));
System.out.println("Watching for changes in [" + res.getSource() + "]");
DefaultFileMonitor monitor = new DefaultFileMonitor(new CustomFSChangeListener(res, config));
monitor.setRecursive(true);
monitor.addFile(listenPath);
monitor.start();
} catch (FileSystemException e) {
e.printStackTrace();
}
}
示例6: startThread
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
/**
* Start a worker thread to listen for directory changes.
*/
public void startThread() {
thread = new Thread(this);
listener = new WatchEventListener(config.getEvents(), config.getFolder());
fm = new DefaultFileMonitor(listener);
fm.setRecursive(false);
fm.addFile(resolvedAbsPath);
fm.start();
log.debug("Monitoring directory: " + resolvedAbsPath.toString());
thread.start();
}
示例7: startThread
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
/**
* Start a worker thread to listen for directory changes.
*/
public void startThread() {
thread = new Thread(this);
listener = new WatchEventListener(config.getEvents(), config.getFolder() + config.getConnection().getPathtomonitor());
fm = new DefaultFileMonitor(listener);
fm.setRecursive(false);
fm.addFile(resolvedAbsPath);
fm.start();
log.debug("Monitoring setup for directory: " + config.getFolder() + config.getConnection().getPathtomonitor());
thread.start();
}
示例8: setFileListener
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
public void setFileListener(File file, EncryptedFileDob dob){
FileObject listendir = null;
try {
FileSystemManager fsManager = VFS.getManager();
listendir = fsManager.resolveFile(file.getPath());
} catch (FileSystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DefaultFileMonitor fm = new DefaultFileMonitor(new FileChangeListener(dob));
fm.setRecursive(true);
fm.addFile(listendir);
fm.start();
}
示例9: testFileCreated
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
public void testFileCreated() throws Exception
{
FileObject fileObj = fsManager.resolveFile(testFile.toURL().toString());
DefaultFileMonitor monitor = new DefaultFileMonitor(new TestFileListener());
monitor.setDelay(100);
monitor.addFile(fileObj);
monitor.start();
writeToFile(testFile);
Thread.sleep(300);
assertTrue("No event occurred", changeStatus != 0);
assertTrue("Incorrect event", changeStatus == 3);
monitor.stop();
}
示例10: testFileDeleted
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
public void testFileDeleted() throws Exception
{
writeToFile(testFile);
FileObject fileObj = fsManager.resolveFile(testFile.toURL().toString());
DefaultFileMonitor monitor = new DefaultFileMonitor(new TestFileListener());
monitor.setDelay(100);
monitor.addFile(fileObj);
monitor.start();
testFile.delete();
Thread.sleep(300);
assertTrue("No event occurred", changeStatus != 0);
assertTrue("Incorrect event", changeStatus == 2);
monitor.stop();
}
示例11: addListener
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
public void addListener(FileObject path, FileListener listener) throws Exception {
stop();
try {
monitor = new DefaultFileMonitor(listener);
monitor.addFile(path);
} finally {
start();
}
}
示例12: watch
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
public void watch() throws FileSystemException {
FileSystemManager manager = VFS.getManager();
FileObject file = manager.resolveFile(
this.compassCompiler.getConfigFile().getParentFile().getAbsolutePath());
DefaultFileMonitor fm = new DefaultFileMonitor(new CompassWatchListener(this.compassCompiler));
fm.setRecursive(true);
fm.setDelay(2000);
fm.addFile(file);
fm.start();
}
示例13: init
import org.apache.commons.vfs2.impl.DefaultFileMonitor; //导入方法依赖的package包/类
public static void init() throws TalesException {
try{
if(!inited){
inited = true;
for(DirListenerObj dirObj : Config.getDirListenerList()){
String dir = dirObj.getDir().replace("~", System.getProperty("user.home"));
FileSystemManager fsManager = VFS.getManager();
FileObject listendir = fsManager.resolveFile(dir);
DefaultFileMonitor fm = new DefaultFileMonitor(new OnChange(dirObj));
fm.setRecursive(true);
fm.addFile(listendir);
fm.start();
}
// prevents the app of exiting
while(true){
Thread.sleep(1000);
}
}
}catch(Exception e){
throw new TalesException(new Throwable(), e);
}
}