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


Java StandardWatchEventKinds.ENTRY_CREATE属性代码示例

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


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

示例1: handleEvent

@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,代码行数:26,代码来源:Watcher.java

示例2: MacOSXWatchKey

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,代码行数:23,代码来源:FSEventWatchService.java

示例3: translateActionToEvent

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,代码行数:17,代码来源:WindowsWatchService.java

示例4: processWatchEvent

/**
 * 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,代码行数:33,代码来源:AdapterLoader.java

示例5: handleEvent

private void handleEvent(final WatchKeyHolder watchKeys, final WatchKey key) throws IOException {
  for (final WatchEvent<?> event : key.pollEvents()) {
    if (event.kind() == StandardWatchEventKinds.OVERFLOW) {
      continue;
    }

    final WatchEvent<Path> watchEvent = cast(event);
    Path path = watchKeys.get(key);
    if (path == null) {
      continue;
    }

    path = path.resolve(watchEvent.context());
    if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
      if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
        watchKeys.register(path);
      }
    } else {
      // Dispatch
      FileEvent fe = toEvent(watchEvent, path);
      if (fe != null) {
        this.eventBus.post(fe);
      }
    }
  }
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:26,代码来源:FileSystemWatcher.java

示例6: MacOSXWatchKey

public MacOSXWatchKey(AbstractWatchService macOSXWatchService, Iterable<? extends WatchEvent.Kind<?>> events) {
  super(macOSXWatchService, null, events);
  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:takari,项目名称:directory-watcher,代码行数:19,代码来源:MacOSXWatchKey.java

示例7: filesFromEvents

private Set<File> filesFromEvents() throws InterruptedException {
  WatchKey key = watcher.take();
  Set<File> files = new LinkedHashSet<File>();
  if (key != null && key.isValid()) 
  {
    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 (log.isDebugEnabled()) {
          log.debug("Watch Event: " + event.kind() + ": " + file);
        }
        if(isJarFile(file))
        {
          files.add(file);
        }
        else
          log.warn("[JAR Loader] Ignoring file "+file);
      }
      
    }
    key.reset();
   
  }
  return files;
}
 
开发者ID:javanotes,项目名称:reactive-data,代码行数:28,代码来源:JarModuleLoader.java

示例8: DirEvent

public DirEvent(final JsonObject json) {
    m_base = Paths.get(json.getString(FIELD_BASE));
    m_file = Paths.get(json.getString(FIELD_FILE));
    m_hash = json.getInteger(FIELD_HASH);
    m_modtm = FileTime.fromMillis(json.getLong(FIELD_MODTM));

    switch (json.getString(FIELD_KIND)) {
        case "ENTRY_CREATE":
            m_kind = StandardWatchEventKinds.ENTRY_CREATE;
            break;
        case "ENTRY_MODIFY":
            m_kind = StandardWatchEventKinds.ENTRY_MODIFY;
            break;
        case "ENTRY_DELETE":
            m_kind = StandardWatchEventKinds.ENTRY_DELETE;
            break;
        default:
            m_kind = null;
            break;
    }
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:21,代码来源:DirEvent.java

示例9: MacOSXWatchKey

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;
}
 
开发者ID:ReactiveX,项目名称:RxJavaFileUtils,代码行数:20,代码来源:MacOSXWatchKey.java

示例10: processSendListEvt

private void processSendListEvt(WatchEvent.Kind<?> kind) throws IOException {
    if ((kind == StandardWatchEventKinds.ENTRY_CREATE)
            || (kind == StandardWatchEventKinds.ENTRY_MODIFY)) {
        if (!isExcelLocked && allowUpdate) {
            // update
            (new UpdateTable()).execute();
            allowUpdate = false;
            retry = false;
            // update table
            log.append("list update."+Constants.NEWLINE);
        } else {
            // set retry
            retry = true;
            log.append("excel file is locked. wait..." + Constants.NEWLINE);
        }
    } else {
        // the DELETE evt
        System.out.println("The sync excel has been deleted");
    }
}
 
开发者ID:smileboywtu,项目名称:CS-FileTransfer,代码行数:20,代码来源:FileTransferClient.java

示例11: _registerDir

/**
 * 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 (s_aLogger.isDebugEnabled ())
    s_aLogger.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);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:22,代码来源:WatchDir.java

示例12: main

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");
}
 
开发者ID:ysc,项目名称:word,代码行数:19,代码来源:DirectoryWatcher.java

示例13: handleEvent

public void handleEvent ( final Path watchable, final WatchEvent<?> event ) throws IOException
{
    final Path path = (Path)event.context ();
    logger.debug ( "Change {} for base: {} on {}", new Object[] { event.kind (), watchable, path } );

    if ( watchable.endsWith ( "native" ) && path.toString ().equals ( "settings.xml" ) )
    {
        if ( event.kind () != StandardWatchEventKinds.ENTRY_DELETE )
        {
            check ();
        }
        else
        {
            storageRemoved ();
        }
    }
    else
    {
        if ( path.toString ().equals ( "settings.xml" ) )
        {
            if ( event.kind () == StandardWatchEventKinds.ENTRY_CREATE )
            {
                this.nativeKey = new File ( watchable.toFile (), "native" ).toPath ().register ( this.watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE );
            }
        }
        else if ( path.toString ().endsWith ( ".hds" ) )
        {
            if ( this.id != null )
            {
                this.storageManager.fileChanged ( this.path.toFile (), this.id, path.toFile () );
            }
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:34,代码来源:BaseWatcher.java

示例14: processFileSystemChanges

private void processFileSystemChanges(final Path watchedDirectory, final WatchKey key) {
    final ChangesProcessor processor = getChangesProcessorOrNull(watchedDirectory);

    if (processor == null) {
        log.warn("Ignoring change in {}: no change processor found", watchedDirectory);
        return;
    }

    processor.start();

    for (WatchEvent<?> event : key.pollEvents()) {
        final WatchEvent.Kind<?> kind = event.kind();
        final Object eventContext = event.context();

        log.debug("Processing {} {} in {}", kind.name(), eventContext, watchedDirectory);

        if (kind == StandardWatchEventKinds.OVERFLOW) {
            log.info("event overflow in {}. Reimporting and registering watchedDirectory '{}' to avoid half synced state",
                    watchedDirectory, watchedDirectory);
            if (Files.exists(watchedDirectory)) {
                registerQuietly(watchedDirectory);
            }
            processor.processChange(kind, watchedDirectory, true);
        } else {
            final Path changedRelPath = (Path) eventContext;
            final Path changedAbsPath = watchedDirectory.resolve(changedRelPath);
            final boolean isDirectory = isDirectory(changedAbsPath, kind);
            if (watchedFiles.matches(changedAbsPath, isDirectory)) {
                if (isDirectory && kind == StandardWatchEventKinds.ENTRY_CREATE) {
                    registerQuietly(changedAbsPath);
                }
                processor.processChange(kind, changedAbsPath, isDirectory);
            } else {
                log.debug("Skipping excluded path {}", changedAbsPath);
            }
        }
    }
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:38,代码来源:FileSystemWatcher.java

示例15: processChange

void processChange(final WatchEvent.Kind<?> kind, final Path changedAbsPath, final boolean isDirectory) {
    if (isDirectory) {
        if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
            listener.directoryCreated(changedAbsPath);
        } else if (kind == StandardWatchEventKinds.ENTRY_MODIFY) {
            listener.directoryModified(changedAbsPath);
        } else if (kind == StandardWatchEventKinds.ENTRY_DELETE) {
            listener.directoryDeleted(changedAbsPath);
        } else if (kind == StandardWatchEventKinds.OVERFLOW) {
            if (Files.exists(changedAbsPath)) {
                log.info("Having an event overflow for '{}'. Entire directory '{}' will be recreated",
                        changedAbsPath, changedAbsPath);
                listener.directoryCreated(changedAbsPath);
            } else {
                log.info("Having an event overflow for non existing directory '{}'. Directory will be removed",
                        changedAbsPath, changedAbsPath);
                listener.directoryDeleted(changedAbsPath);
            }
        }
    } else {
        if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
            listener.fileCreated(changedAbsPath);
        } else if (kind == StandardWatchEventKinds.ENTRY_MODIFY) {
            listener.fileModified(changedAbsPath);
        } else if (kind == StandardWatchEventKinds.ENTRY_DELETE) {
            listener.fileDeleted(changedAbsPath);
        } else if (kind == StandardWatchEventKinds.OVERFLOW) {
            throw new IllegalStateException("Only a directory should even possibly overflow in events, for example" +
                    " by saving 1000 new files in one go.");
        }
    }
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:32,代码来源:FileSystemWatcher.java


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