Java Code Examples for java.nio.file.StandardWatchEventKinds#ENTRY_MODIFY
The following examples show how to use
java.nio.file.StandardWatchEventKinds#ENTRY_MODIFY .
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: MacOSXWatchKey.java From RxJavaFileUtils with Apache License 2.0 | 6 votes |
public MacOSXWatchKey(Path path, AbstractWatchService macOSXWatchService, WatchEvent.Kind<?>[] events) { super(macOSXWatchService); this.path = path; 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; }
Example 2
Source File: WindowsWatchService.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 } }
Example 3
Source File: Watcher.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
@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 ); } }
Example 4
Source File: WatchDir.java From ph-commons with Apache License 2.0 | 6 votes |
/** * Register the given directory with the WatchService * * @param aDir * Directory to be watched. May not be <code>null</code>. */ private void _registerDir (@Nonnull final Path aDir) throws IOException { if (LOGGER.isDebugEnabled ()) LOGGER.debug ("Register directory " + aDir + (m_bRecursive && !m_bRegisterRecursiveManually ? " (recursively)" : "")); final WatchEvent.Kind <?> [] aKinds = new WatchEvent.Kind <?> [] { StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY }; // throws exception when using with modifiers even if null final WatchKey aKey = m_aModifiers != null ? aDir.register (m_aWatcher, aKinds, m_aModifiers) : aDir.register (m_aWatcher, aKinds); m_aKeys.put (aKey, aDir); }
Example 5
Source File: WindowsWatchService.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 } }
Example 6
Source File: DirectoryWatcher.java From word with Apache License 2.0 | 6 votes |
public static void main(String[] args) { DirectoryWatcher dictionaryWatcher = new DirectoryWatcher(new WatcherCallback(){ private long lastExecute = System.currentTimeMillis(); @Override public void execute(WatchEvent.Kind<?> kind, String path) { if(System.currentTimeMillis() - lastExecute > 1000){ lastExecute = System.currentTimeMillis(); //刷新词典 System.out.println("事件:"+kind.name()+" ,路径:"+path); } } }, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE); //监控DIC目录及其所有子目录的子目录...递归 dictionaryWatcher.watchDirectoryTree("d:/DIC"); //只监控DIC2目录 dictionaryWatcher.watchDirectory("d:/DIC2"); }
Example 7
Source File: WindowsWatchService.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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 } }
Example 8
Source File: FSEventWatchService.java From cyberduck with GNU General Public License v3.0 | 6 votes |
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; }
Example 9
Source File: WindowsWatchService.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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 } }
Example 10
Source File: WindowsWatchService.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 } }
Example 11
Source File: MacOSXWatchKey.java From directory-watcher with Apache License 2.0 | 6 votes |
public MacOSXWatchKey( AbstractWatchService macOSXWatchService, Iterable<? extends WatchEvent.Kind<?>> events, int queueSize) { super(macOSXWatchService, null, events, queueSize); 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; }
Example 12
Source File: WindowsWatchService.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 } }
Example 13
Source File: WindowsWatchService.java From hottub with GNU General Public License v2.0 | 6 votes |
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 } }
Example 14
Source File: FileSystemWatcher.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Process watch events. * * @param key the key * @param keys the keys */ private void processWatchEvents(WatchKey key, List<WatchEvent<?>> keys) { for (WatchEvent<?> watchEvent : keys) { Kind<?> watchEventKind = watchEvent.kind(); // Sometimes events are created faster than they are registered // or the implementation may specify a maximum number of events // and further events are discarded. In these cases an event of // kind overflow is returned. We ignore this case for now if (watchEventKind == StandardWatchEventKinds.OVERFLOW) { continue; } Path dir = (Path) key.watchable(); Path fullPath = dir.resolve((Path) watchEvent.context()); FileWatcherUpdateInterface parentObj = watcherMap.get(key); if (parentObj != null) { if (watchEventKind == StandardWatchEventKinds.ENTRY_CREATE) { // A new file has been created parentObj.fileAdded(fullPath); } else if (watchEventKind == StandardWatchEventKinds.ENTRY_MODIFY) { ReloadManager.getInstance().fileModified(fullPath); // The file has been modified. parentObj.fileModified(fullPath); } else if (watchEventKind == StandardWatchEventKinds.ENTRY_DELETE) { parentObj.fileDeleted(fullPath); } } } }
Example 15
Source File: ConfigUpdater.java From cellery-security with Apache License 2.0 | 5 votes |
public void run() { log.info("Running configuration updater.."); String configFilePath = CellStsUtils.getConfigFilePath(); Path directoryPath = Paths.get(configFilePath.substring(0, configFilePath.lastIndexOf("/"))); try { while (true) { WatchService watcher = directoryPath.getFileSystem().newWatchService(); directoryPath.register(watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY); log.debug("Waiting for config file change"); WatchKey watckKey = watcher.take(); List<WatchEvent<?>> events = watckKey.pollEvents(); log.debug("Received events: ...."); for (WatchEvent event : events) { if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) { log.info("Updating file on {} event", StandardWatchEventKinds.ENTRY_CREATE); CellStsUtils.buildCellStsConfiguration(); CellStsUtils.readUnsecuredContexts(); } if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) { log.info("Updating file on {} event", StandardWatchEventKinds.ENTRY_MODIFY); CellStsUtils.buildCellStsConfiguration(); CellStsUtils.readUnsecuredContexts(); } } } } catch (IOException | InterruptedException | CelleryCellSTSException e) { log.error("Error while updating configurations on file change ", e); } }
Example 16
Source File: PollingWatchService.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Register the given file with this watch service */ @Override WatchKey register(final Path path, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { // check events - CCE will be thrown if there are invalid elements final Set<WatchEvent.Kind<?>> eventSet = new HashSet<>(events.length); for (WatchEvent.Kind<?> event: events) { // standard events if (event == StandardWatchEventKinds.ENTRY_CREATE || event == StandardWatchEventKinds.ENTRY_MODIFY || event == StandardWatchEventKinds.ENTRY_DELETE) { eventSet.add(event); continue; } // OVERFLOW is ignored if (event == StandardWatchEventKinds.OVERFLOW) { continue; } // null/unsupported if (event == null) throw new NullPointerException("An element in event set is 'null'"); throw new UnsupportedOperationException(event.name()); } if (eventSet.isEmpty()) throw new IllegalArgumentException("No events to register"); // Extended modifiers may be used to specify the sensitivity level int sensitivity = 10; if (modifiers.length > 0) { for (WatchEvent.Modifier modifier: modifiers) { if (modifier == null) throw new NullPointerException(); if (ExtendedOptions.SENSITIVITY_HIGH.matches(modifier)) { sensitivity = ExtendedOptions.SENSITIVITY_HIGH.parameter(); } else if (ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier)) { sensitivity = ExtendedOptions.SENSITIVITY_MEDIUM.parameter(); } else if (ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) { sensitivity = ExtendedOptions.SENSITIVITY_LOW.parameter(); } else { throw new UnsupportedOperationException("Modifier not supported"); } } } // check if watch service is closed if (!isOpen()) throw new ClosedWatchServiceException(); // registration is done in privileged block as it requires the // attributes of the entries in the directory. try { int value = sensitivity; return AccessController.doPrivileged( new PrivilegedExceptionAction<PollingWatchKey>() { @Override public PollingWatchKey run() throws IOException { return doPrivilegedRegister(path, eventSet, value); } }); } catch (PrivilegedActionException pae) { Throwable cause = pae.getCause(); if (cause != null && cause instanceof IOException) throw (IOException)cause; throw new AssertionError(pae); } }
Example 17
Source File: PollingWatchService.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Register the given file with this watch service */ @Override WatchKey register(final Path path, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException { // check events - CCE will be thrown if there are invalid elements final Set<WatchEvent.Kind<?>> eventSet = new HashSet<>(events.length); for (WatchEvent.Kind<?> event: events) { // standard events if (event == StandardWatchEventKinds.ENTRY_CREATE || event == StandardWatchEventKinds.ENTRY_MODIFY || event == StandardWatchEventKinds.ENTRY_DELETE) { eventSet.add(event); continue; } // OVERFLOW is ignored if (event == StandardWatchEventKinds.OVERFLOW) { continue; } // null/unsupported if (event == null) throw new NullPointerException("An element in event set is 'null'"); throw new UnsupportedOperationException(event.name()); } if (eventSet.isEmpty()) throw new IllegalArgumentException("No events to register"); // Extended modifiers may be used to specify the sensitivity level int sensitivity = 10; if (modifiers.length > 0) { for (WatchEvent.Modifier modifier: modifiers) { if (modifier == null) throw new NullPointerException(); if (ExtendedOptions.SENSITIVITY_HIGH.matches(modifier)) { sensitivity = ExtendedOptions.SENSITIVITY_HIGH.parameter(); } else if (ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier)) { sensitivity = ExtendedOptions.SENSITIVITY_MEDIUM.parameter(); } else if (ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) { sensitivity = ExtendedOptions.SENSITIVITY_LOW.parameter(); } else { throw new UnsupportedOperationException("Modifier not supported"); } } } // check if watch service is closed if (!isOpen()) throw new ClosedWatchServiceException(); // registration is done in privileged block as it requires the // attributes of the entries in the directory. try { int value = sensitivity; return AccessController.doPrivileged( new PrivilegedExceptionAction<PollingWatchKey>() { @Override public PollingWatchKey run() throws IOException { return doPrivilegedRegister(path, eventSet, value); } }); } catch (PrivilegedActionException pae) { Throwable cause = pae.getCause(); if (cause != null && cause instanceof IOException) throw (IOException)cause; throw new AssertionError(pae); } }
Example 18
Source File: FileMonitorConfiguration.java From spring-cloud-config with Apache License 2.0 | 4 votes |
private Set<File> filesFromEvents() { Set<File> files = new LinkedHashSet<File>(); if (this.watcher == null) { return files; } WatchKey key = this.watcher.poll(); while (key != null) { for (WatchEvent<?> event : key.pollEvents()) { if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE || event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) { Path item = (Path) event.context(); File file = new File(((Path) key.watchable()).toAbsolutePath() + File.separator + item.getFileName()); if (file.isDirectory()) { files.addAll(walkDirectory(file.toPath())); } else { if (!file.getPath().contains(".git") && !PatternMatchUtils .simpleMatch(this.excludes, file.getName())) { if (log.isDebugEnabled()) { log.debug("Watch Event: " + event.kind() + ": " + file); } files.add(file); } } } else if (event.kind() == StandardWatchEventKinds.OVERFLOW) { if (log.isDebugEnabled()) { log.debug("Watch Event: " + event.kind() + ": context: " + event.context()); } if (event.context() != null && event.context() instanceof Path) { files.addAll(walkDirectory((Path) event.context())); } else { for (Path path : this.directory) { files.addAll(walkDirectory(path)); } } } else { if (log.isDebugEnabled()) { log.debug("Watch Event: " + event.kind() + ": context: " + event.context()); } } } key.reset(); key = this.watcher.poll(); } return files; }
Example 19
Source File: PathsWatcher.java From scenic-view with GNU General Public License v3.0 | 4 votes |
public void watch() { watcherThread = new Thread(new Runnable() { @Override public void run() { logger(PathsWatcher.class).info("starting to monitor physical files"); while (true) { WatchKey key; try { key = watchService.take(); } catch (InterruptedException ex) { return; } Path directory = ((Path) key.watchable()).toAbsolutePath().normalize(); for (WatchEvent<?> event : key.pollEvents()) { WatchEvent.Kind<?> kind = event.kind(); logger(PathsWatcher.class).debug("'%s' change detected in directory %s", kind, directory); if (kind == StandardWatchEventKinds.ENTRY_MODIFY) { // it is a modification @SuppressWarnings("unchecked") WatchEvent<Path> ev = (WatchEvent<Path>) event; Path modifiedFile = directory.resolve(ev.context()).toAbsolutePath().normalize(); if (filesActions.containsKey(directory.toString())) { logger(PathsWatcher.class).debug("file: %s was modified", modifiedFile.getFileName()); Map<String, List<Runnable>> filesAction = filesActions.get(directory.toString()); if (filesAction.containsKey(modifiedFile.toString())) { logger(PathsWatcher.class).debug("file is monitored"); List<Runnable> actions = filesAction.get(modifiedFile.toString()); logger(PathsWatcher.class).debug("%d CSS modification will be performed ", actions.size()); for (Runnable action : actions) { action.run(); } } else { logger(PathsWatcher.class).debug("file is not monitored"); } } } } boolean valid = key.reset(); if (!valid) { break; } } } }, "CSSFX-file-monitor"); watcherThread.setDaemon(true); watcherThread.start(); }
Example 20
Source File: Watchdir.java From verigreen with Apache License 2.0 | 4 votes |
@Override public void run() { FileReader reader = null; Properties properties = new Properties(); for(;;){ try { WatchService watcher = myDir.getFileSystem().newWatchService(); myDir.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY); WatchKey watckKey = watcher.take(); List<WatchEvent<?>> events = watckKey.pollEvents(); for (WatchEvent<?> event : events) { if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) { VerigreenLogger.get().log( getClass().getName(), RuntimeUtils.getCurrentMethodName(), "Modify: " + event.context().toString()); reader = new FileReader(path + "/config.properties"); properties.load(reader); String protectedBranches=properties.getProperty("git.protectedBranches"); String permittedUsers=properties.getProperty("git.permittedUsers"); String jobName=properties.getProperty("jenkins.jobName"); String fullPush=properties.getProperty("full.push"); //If the value is null then add it from the prop file to the hash map. This is important in case reading the value when a first push happened after changing the job name if((VerigreenNeededLogic.VerigreenMap.get("_jobName") == null) || (!VerigreenNeededLogic.VerigreenMap.get("_jobName").equals(jobName))){ VerigreenNeededLogic.VerigreenMap.put("_jobName", jobName); JenkinsVerifier.job2Verify = JenkinsVerifier.getJobToVerify(); } if(!VerigreenNeededLogic.VerigreenMap.get("_protectedBranches").equals(protectedBranches)){ VerigreenNeededLogic.VerigreenMap.put("_protectedBranches", protectedBranches); } if(!VerigreenNeededLogic.VerigreenMap.get("_permittedUsers").equals(permittedUsers)){ VerigreenNeededLogic.VerigreenMap.put("_permittedUsers", permittedUsers); } if(!VerigreenNeededLogic.VerigreenMap.get("_fullPush").equals(fullPush)){ VerigreenNeededLogic.VerigreenMap.put("_fullPush", fullPush); } } } } catch( Exception e) { e.printStackTrace ( ); } } }