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


Java StandardWatchEventKinds类代码示例

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


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

示例1: watch

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
private void watch() {
    try {
        WatchService watchService = directoryPath.getFileSystem().newWatchService();
        directoryPath.register(watchService, StandardWatchEventKinds.ENTRY_CREATE,
                StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE);
        while (true) {
            WatchKey watchKey = watchService.take();
            for (final WatchEvent<?> event : watchKey.pollEvents()) {
                takeActionOnChangeEvent(event);
            }
        }

    } catch (InterruptedException interruptedException) {
        System.out.println("Thread got interrupted:" + interruptedException);
    } catch (Exception exception) {
        exception.printStackTrace();
    }

}
 
开发者ID:patexoid,项目名称:ZombieLib2,代码行数:20,代码来源:DirWatcherService.java

示例2: handleEvent

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
@SuppressWarnings ( "unchecked" )
private void handleEvent ( final WatchEvent<?> event )
{
    final Kind<?> kind = event.kind ();

    if ( kind == StandardWatchEventKinds.OVERFLOW )
    {
        // FIXME: full rescan
        return;
    }

    final Path path = this.path.resolve ( ( (WatchEvent<Path>)event ).context () );

    if ( kind == StandardWatchEventKinds.ENTRY_CREATE )
    {
        this.listener.event ( path, Event.ADDED );
    }
    else if ( kind == StandardWatchEventKinds.ENTRY_DELETE )
    {
        this.listener.event ( path, Event.REMOVED );
    }
    else if ( kind == StandardWatchEventKinds.ENTRY_MODIFY )
    {
        this.listener.event ( path, Event.MODIFIED );
    }
}
 
开发者ID:eclipse,项目名称:packagedrone,代码行数:27,代码来源:Watcher.java

示例3: run

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
@Override
public void run() {
    while (true) {
        try {
            WatchKey key = watchService.take();

            if (key == trustedKey) {
                for (WatchEvent<?> watchEvent : key.pollEvents()) {
                    WatchEvent.Kind<?> kind = watchEvent.kind();

                    if (kind != StandardWatchEventKinds.OVERFLOW) {
                        synchronizeTrustedCertificates();
                    }
                }
            }

            if (!key.reset()) {
                break;
            }
        } catch (InterruptedException e) {
            logger.error("Watcher interrupted.", e);
        }
    }
}
 
开发者ID:digitalpetri,项目名称:opc-ua-stack,代码行数:25,代码来源:DefaultCertificateValidator.java

示例4: StorageWatcher

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
public StorageWatcher ( final StorageManager storageManager, final BaseWatcher baseWatcher, final Path path, final WatchService watcher ) throws IOException
{
    this.storageManager = storageManager;
    this.baseWatcher = baseWatcher;
    this.watcher = watcher;
    this.path = path;

    this.key = path.register ( watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY );
    baseWatcher.addWatcherMap ( path, this );

    final File nativeDir = new File ( path.toFile (), "native" );
    baseWatcher.addWatcherMap ( nativeDir.toPath (), this );

    logger.debug ( "Checking native dir: {}", nativeDir );

    if ( nativeDir.exists () && nativeDir.isDirectory () )
    {
        this.nativeKey = nativeDir.toPath ().register ( this.watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE );
        check ();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:BaseWatcher.java

示例5: BaseWatcher

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
public BaseWatcher ( final StorageManager storageManager, final File base ) throws IOException
{
    this.storageManager = storageManager;
    this.base = base.toPath ();
    this.watcher = FileSystems.getDefault ().newWatchService ();

    this.baseKey = base.toPath ().register ( this.watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE );

    logger.debug ( "Checking for initial storages" );

    for ( final File child : this.base.toFile ().listFiles () )
    {
        logger.debug ( "Found initial storage dir - {}", child );
        checkAddStorage ( child.toPath () );
    }

    startWatcher ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:BaseWatcher.java

示例6: setWatcherOnThemeFile

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
private static void setWatcherOnThemeFile() {
    try {
        WatchService watchService = FileSystems.getDefault().newWatchService();
        WatchKey watchKey = path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
        while (true) {
            final WatchKey wk = watchService.take();
            for (WatchEvent<?> event : wk.pollEvents()) {
                //we only register "ENTRY_MODIFY" so the context is always a Path.
                final Path changed = (Path) event.context();
                System.out.println(changed);
                if (changed.endsWith("Theme.css")) {
                    System.out.println("Theme.css has changed...reloading stylesheet.");
                    scene.getStylesheets().clear();
                    scene.getStylesheets().add("resources/Theme.css");
                }
            }
            boolean valid = wk.reset();
            if (!valid)
                System.out.println("Watch Key has been reset...");
        }
    } catch (Exception e) { /*Thrown to void*/ }
}
 
开发者ID:maximstewart,项目名称:UDE,代码行数:23,代码来源:UFM.java

示例7: run

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void run() {
	while (running) {
		try {
			final WatchKey watchKey = watcher.take();
			for (final WatchEvent<?> event : watchKey.pollEvents()) {
				Path changed = (Path) event.context();
				if (changed == null || event.kind() == StandardWatchEventKinds.OVERFLOW) {
					System.out.println("bad file watch event: " + event);
					continue;
				}
				changed = watchedDirectory.resolve(changed);
				for (final ListenerAndPath x : listeners) {
					if (Thread.interrupted() && !running)
						return;
					if (changed.startsWith(x.startPath)) {
						x.listener.fileChanged(changed, (Kind<Path>) event.kind());
					}
				}
			}
			watchKey.reset();
		} catch (final InterruptedException e) {}
	}
}
 
开发者ID:Njol,项目名称:Motunautr,代码行数:26,代码来源:FileWatcher.java

示例8: simpleTest

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
public void simpleTest(Path path) throws Exception
{
	WatchService watchService=FileSystems.getDefault().newWatchService();  
	path.register(watchService,   
            StandardWatchEventKinds.ENTRY_CREATE,  
            StandardWatchEventKinds.ENTRY_DELETE,  
            StandardWatchEventKinds.ENTRY_MODIFY);  
    while(true)  
    {  
        WatchKey watchKey=watchService.take();  
           List<WatchEvent<?>> watchEvents = watchKey.pollEvents();  
           for(WatchEvent<?> event : watchEvents){  
               //TODO 根据事件类型采取不同的操作。。。。。。。  
               System.out.println("["+event.context()+"]文件发生了["+event.kind()+"]事件");    
           }  
           watchKey.reset(); 
    } 
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:19,代码来源:FileMonitorJdkImpl.java

示例9: MacOSXWatchKey

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
public MacOSXWatchKey(final Watchable file, final FSEventWatchService service, final WatchEvent.Kind<?>[] events) {
    super(service);
    this.file = file;

    boolean reportCreateEvents = false;
    boolean reportModifyEvents = false;
    boolean reportDeleteEvents = false;

    for(WatchEvent.Kind<?> event : events) {
        if(event == StandardWatchEventKinds.ENTRY_CREATE) {
            reportCreateEvents = true;
        }
        else if(event == StandardWatchEventKinds.ENTRY_MODIFY) {
            reportModifyEvents = true;
        }
        else if(event == StandardWatchEventKinds.ENTRY_DELETE) {
            reportDeleteEvents = true;
        }
    }
    this.reportCreateEvents = reportCreateEvents;
    this.reportDeleteEvents = reportDeleteEvents;
    this.reportModifyEvents = reportModifyEvents;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:24,代码来源:FSEventWatchService.java

示例10: CORSConfigurationFileWatcher

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
/**
 * Creates a new CORS filter configuration watcher.
 *
 * @param filterConfig The filter configuration. Must not be
 *                     {@code null}.
 */
public CORSConfigurationFileWatcher(final FilterConfig filterConfig) {

	if (filterConfig == null) {
		throw new IllegalArgumentException("The servlet filter configuration must not be null");
	}

	this.filterConfig = filterConfig;

	try {
		watcher = FileSystems.getDefault().newWatchService();
		Path dir = determineConfigDir();
		dir.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
		LOG.fine("CORS Filter: Started watching for configuration file changes within " + dir);
	} catch (IOException e) {
		LOG.severe("CORS Filter: Failed to initialize file system watcher: " + e.getMessage());
	}
}
 
开发者ID:sdcuike,项目名称:cors-filter,代码行数:24,代码来源:CORSConfigurationFileWatcher.java

示例11: FileWatcher

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
private FileWatcher(Map<Path, Consumer<Path>> registeredPaths) {
  this.registeredPaths = ImmutableMap.copyOf(registeredPaths);
  try {
    watchService = FileSystems.getDefault().newWatchService();
    ImmutableMap.Builder<WatchKey, Path> watchedDirsBuilder = ImmutableMap.builder();
    for (Map.Entry<Path, Consumer<Path>> entry : registeredPaths.entrySet()) {
      Path dir = entry.getKey().getParent();
      WatchKey key =
          dir.register(
              watchService,
              StandardWatchEventKinds.ENTRY_CREATE,
              StandardWatchEventKinds.ENTRY_DELETE,
              StandardWatchEventKinds.ENTRY_MODIFY);
      watchedDirsBuilder.put(key, dir);
    }
    this.watchedDirs = watchedDirsBuilder.build();
  } catch (IOException e) {
    throw new UncheckedIOException("Could not create WatchService.", e);
  }
  executor = Executors.newSingleThreadScheduledExecutor();
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:22,代码来源:FileWatcher.java

示例12: translateActionToEvent

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
private WatchEvent.Kind<?> translateActionToEvent(int action) {
    switch (action) {
        case FILE_ACTION_MODIFIED :
            return StandardWatchEventKinds.ENTRY_MODIFY;

        case FILE_ACTION_ADDED :
        case FILE_ACTION_RENAMED_NEW_NAME :
            return StandardWatchEventKinds.ENTRY_CREATE;

        case FILE_ACTION_REMOVED :
        case FILE_ACTION_RENAMED_OLD_NAME :
            return StandardWatchEventKinds.ENTRY_DELETE;

        default :
            return null;  // action not recognized
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:WindowsWatchService.java

示例13: test

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
/**
 * Create a WatchService to watch for changes in the given directory
 * and then attempt to close the WatchService and change a registration
 * at the same time.
 */
static void test(Path dir, ExecutorService pool) throws Exception {
    WatchService watcher = FileSystems.getDefault().newWatchService();

    // initial registration
    dir.register(watcher, StandardWatchEventKinds.ENTRY_CREATE);

    // submit tasks to close the WatchService and update the registration
    Future<Void> closeResult;
    Future<Boolean> registerResult;

    if (RAND.nextBoolean()) {
        closeResult = pool.submit(newCloserTask(watcher));
        registerResult = pool.submit(newRegisterTask(watcher, dir));
    } else {
        registerResult = pool.submit(newRegisterTask(watcher, dir));
        closeResult = pool.submit(newCloserTask(watcher));
    }

    closeResult.get();
    registerResult.get();

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:LotsOfCloses.java

示例14: processWatchEvent

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
/**
 * Handles a watchevent, it currently only handles the DELETE and MODIFY - create isn't handled
 * as when you create a new file you get two events - one of the create and one for the modify,
 * therefore it can be safely handled in the modify only.
 *
 * If the delete corresponds to a adapter loaded - it deregisterWithAdapterManager it with the
 * adatperManager If the modify is new / modified it passes it to the load method that handles
 * re-registering existing adapters
 *
 * @param event
 */
public void processWatchEvent(final WatchEvent<?> event) {
    synchronized (propertiesToAdapter) {
        if (LOG.isInfoEnabled()) {
            LOG.info("Logging watch event:" + event.kind() + ": " + event.context());
        }
        // check it is ended with .properties
        if (isPropertyFile(event)) {
            String path = ((Path) event.context()).toString();
            Adapter adapter = propertiesToAdapter.get(path);
            // if we have already seen this then deregister it
            if (adapter != null) {
                removeAdapter(path, adapter);
            }

            if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE
                    || event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
                File file = new File(getPathToWatch().toString(), ((Path) event.context()).toString());
                load(file);
            }
        }
    }
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:34,代码来源:AdapterLoader.java

示例15: processEvent

import java.nio.file.StandardWatchEventKinds; //导入依赖的package包/类
/** Notify file system event. */
void processEvent() {
	while(true) {
		WatchKey signal;
		
		try {
			signal = watcher.take();
		} catch (InterruptedException e) {
			return;
		}
		
		for(WatchEvent<?> event : signal.pollEvents()) {
			Kind<?> kind = event.kind();
			
			if(kind == StandardWatchEventKinds.OVERFLOW) {
				continue;
			}
			
			Path name = (Path)event.context();
			notify(name.toAbsolutePath().toString(), kind);
		}
		
		key.reset();
	}
}
 
开发者ID:yoking-zhang,项目名称:demo,代码行数:26,代码来源:DirectoryWatcher.java


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