com.sun.nio.file.ExtendedWatchEventModifier Java Examples
The following examples show how to use
com.sun.nio.file.ExtendedWatchEventModifier.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WindowsPath.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #2
Source File: WindowsPath.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #3
Source File: WindowsPath.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #4
Source File: WindowsPath.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #5
Source File: WindowsPath.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #6
Source File: DirectoryWatcher.java From directory-watcher with Apache License 2.0 | 5 votes |
private void register(Path directory, boolean useFileTreeModifier) throws IOException { logger.debug("Registering [{}].", directory); Watchable watchable = isMac ? new WatchablePath(directory) : directory; WatchEvent.Modifier[] modifiers = useFileTreeModifier ? new WatchEvent.Modifier[] {ExtendedWatchEventModifier.FILE_TREE} : new WatchEvent.Modifier[] {}; WatchEvent.Kind<?>[] kinds = new WatchEvent.Kind<?>[] {ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY}; WatchKey watchKey = watchable.register(watchService, kinds, modifiers); keyRoots.put(watchKey, directory); }
Example #7
Source File: WindowsPath.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #8
Source File: WindowsPath.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #9
Source File: WindowsPath.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #10
Source File: WindowsPath.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #11
Source File: WindowsPath.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #12
Source File: WindowsPath.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #13
Source File: WindowsPath.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Override public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { if (watcher == null) throw new NullPointerException(); if (!(watcher instanceof WindowsWatchService)) throw new ProviderMismatchException(); // When a security manager is set then we need to make a defensive // copy of the modifiers and check for the Windows specific FILE_TREE // modifier. When the modifier is present then check that permission // has been granted recursively. SecurityManager sm = System.getSecurityManager(); if (sm != null) { boolean watchSubtree = false; final int ml = modifiers.length; if (ml > 0) { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { watchSubtree = true; break; } } } String s = getPathForPermissionCheck(); sm.checkRead(s); if (watchSubtree) sm.checkRead(s + "\\-"); } return ((WindowsWatchService)watcher).register(this, events, modifiers); }
Example #14
Source File: DefaultFileWatcher.java From MSPaintIDE with MIT License | 4 votes |
@Override public FileWatcher startWatching() { this.watching = true; this.watchingFuture = executor.submit(() -> { try (WatchService watchService = FileSystems.getDefault().newWatchService()) { this.file.toPath().register(watchService, new WatchEvent.Kind<?>[]{StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE}, ExtendedWatchEventModifier.FILE_TREE); var cooldownMap = new HashMap<File, Long>(); var lastActionMap = new HashMap<File, WatchType>(); while (true) { var watchKey = watchService.take(); Map<WatchType, File> found = null; for (var event : watchKey.pollEvents()) { var dir = (Path) watchKey.watchable(); var changed = dir.resolve((Path) event.context()).toFile(); if (hasCovered(changed)) { if (found == null) found = new HashMap<>(); found.put(WatchType.fromKind(event.kind()), changed); } } if (found != null) { found.forEach((type, file) -> { if (!keepFromFilters(file)) return; if (compareTypes(lastActionMap.get(file), type) && System.currentTimeMillis() - cooldownMap.getOrDefault(file, 0L) < MIN_TIME_IN_MILLS) return; lastActionMap.put(file, type); cooldownMap.put(file, System.currentTimeMillis()); this.fileListeners.values().forEach(listener -> listener.accept(type, file)); }); } if (!watchKey.reset()) { LOGGER.info("Key has been unregistered"); } } } catch (IOException e) { LOGGER.error("An exception has occurred in a FileWatcher!", e); } catch (InterruptedException ignored) {} }); return this; }