java.nio.file.Path.register()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(209)

本文整理了Java中java.nio.file.Path.register()方法的一些代码示例,展示了Path.register()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Path.register()方法的具体详情如下:
包路径:java.nio.file.Path
类名称:Path
方法名:register

Path.register介绍

暂无

代码示例

代码示例来源:origin: jersey/jersey

private void registerWatcher(WatchService watcher, Path directory) throws IOException {
  directory.register(watcher,
      new WatchEvent.Kind[]{
          StandardWatchEventKinds.ENTRY_MODIFY
      },
      SensitivityWatchEventModifier.HIGH);
}

代码示例来源:origin: apache/groovy

@Override
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) throws IOException {
  return delegate.register(watcher, events);
}

代码示例来源:origin: lets-blade/blade

private void register(Path dir) throws IOException{
  WatchKey key = dir.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
  pathMap.put(key,dir);
}

代码示例来源:origin: lets-blade/blade

private void register(Path dir) throws IOException{
  WatchKey key = dir.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
  pathMap.put(key,dir);
}

代码示例来源:origin: jooby-project/jooby

/**
 * Register the given directory with the WatchService
 */
private void register(final Path dir) throws IOException {
 WatchKey key = dir
   .register(watcher, new Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY}, HIGH);
 keys.put(key, dir);
}

代码示例来源:origin: jooby-project/jooby

/**
 * Register the given directory with the WatchService
 */
private void register(final Path dir) throws IOException {
 WatchKey key = dir.register(watcher, new Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY }, HIGH);
 keys.put(key, dir);
}

代码示例来源:origin: wildfly/wildfly

private void addWatchedDirectory(PathData data, File dir) throws IOException {
  Path path = Paths.get(dir.toURI());
  WatchKey key = path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
  pathDataByKey.put(key, data);
  data.keys.add(key);
}

代码示例来源:origin: neo4j/neo4j

@Override
public WatchedResource watch( File file ) throws IOException
{
  if ( !file.isDirectory() )
  {
    throw new IllegalArgumentException( format( "File `%s` is not a directory. Only directories can be " +
        "registered to be monitored.", file.getCanonicalPath() ) );
  }
  WatchKey watchKey = file.toPath().register( watchService, OBSERVED_EVENTS, SensitivityWatchEventModifier.HIGH );
  return new WatchedFile( watchKey );
}

代码示例来源:origin: syncany/syncany

private synchronized void registerWatch(Path dir) {
  if (!watchPathKeyMap.containsKey(dir)) {
    logger.log(Level.INFO, "- Registering " + dir);
    try {
      WatchKey watchKey = dir.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY, OVERFLOW);
      watchPathKeyMap.put(dir, watchKey);
    }
    catch (IOException e) {
      logger.log(Level.FINE, "IO Failed", e);
    }
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-config

private void registerWatch(Path dir) throws IOException {
  if (log.isDebugEnabled()) {
    log.debug("registering: " + dir + " for file creation events");
  }
  try {
  dir.register(this.watcher, StandardWatchEventKinds.ENTRY_CREATE,
      StandardWatchEventKinds.ENTRY_MODIFY);
  } catch (IOException e) {
    throw e;
  } catch (Exception e) {
    throw new IOException("Cannot register watcher for " + dir, e);
  }
}

代码示例来源:origin: konsoletyper/teavm

private void registerSingle(Path path) throws IOException {
  WatchKey key = path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE,
      StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY);
  keysToPath.put(key, path);
  pathsToKey.put(path, key);
  refCount.put(path, refCount.getOrDefault(path, 0) + 1);
  Path parent = path.getParent();
  refCount.put(parent, refCount.getOrDefault(parent, 0) + 1);
}

代码示例来源:origin: dreamhead/moco

private WatchKey registerDirectory(final Path directory) {
  if (directoryToKey.containsKey(directory)) {
    return directoryToKey.get(directory);
  }
  try {
    WatchKey key = directory.register(service, new WatchEvent.Kind[]{ENTRY_MODIFY}, HIGH);
    directoryToKey.put(directory, key);
    return key;
  } catch (IOException e) {
    throw new MocoException(e);
  }
}

代码示例来源:origin: apache/zeppelin

public void watch(File file) throws IOException {
 String dirString;
 if (file.isFile()) {
  dirString = file.getParentFile().getAbsolutePath();
 } else {
  throw new IOException(file.getName() + " is not a file");
 }
 if (dirString == null) {
  dirString = "/";
 }
 Path dir = FileSystems.getDefault().getPath(dirString);
 logger.info("watch " + dir);
 WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
 synchronized (watchKeys) {
  watchKeys.put(key, new File(dirString));
  watchFiles.add(file);
 }
}

代码示例来源:origin: apache/zookeeper

/**
 * Creates a watcher that watches <code>dirPath</code> and invokes <code>callback</code> on changes.
 *
 * @param dirPath the directory to watch.
 * @param callback the callback to invoke with events. <code>event.kind()</code> will return the type of event,
 *                 and <code>event.context()</code> will return the filename relative to <code>dirPath</code>.
 * @throws IOException if there is an error creating the WatchService.
 */
public FileChangeWatcher(Path dirPath, Consumer<WatchEvent<?>> callback) throws IOException {
  FileSystem fs = dirPath.getFileSystem();
  WatchService watchService = fs.newWatchService();
  if (LOG.isDebugEnabled()) {
    LOG.debug("Registering with watch service: " + dirPath);
  }
  dirPath.register(
      watchService,
      new WatchEvent.Kind<?>[]{
          StandardWatchEventKinds.ENTRY_CREATE,
          StandardWatchEventKinds.ENTRY_DELETE,
          StandardWatchEventKinds.ENTRY_MODIFY,
          StandardWatchEventKinds.OVERFLOW},
      SensitivityWatchEventModifier.HIGH);
  state = State.NEW;
  this.watcherThread = new WatcherThread(watchService, callback);
  this.watcherThread.setDaemon(true);
}

代码示例来源:origin: jooby-project/jooby

private void register(final Path path, final FileEventOptions options) throws IOException {
 Kind<?>[] kinds = options.kinds();
 Modifier modifier = options.modifier();
 WatchKey key = path.register(watcher, kinds, modifier);
 this.keys.put(key, path);
 this.options.put(path, options);
}

代码示例来源:origin: stackoverflow.com

final Path path = FileSystems.getDefault().getPath(System.getProperty("user.home"), "Desktop");
System.out.println(path);
try (final WatchService watchService = FileSystems.getDefault().newWatchService()) {
  final 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("myFile.txt")) {
        System.out.println("My file has changed");
      }
    }
    // reset the key
    boolean valid = wk.reset();
    if (!valid) {
      System.out.println("Key has been unregisterede");
    }
  }
}

代码示例来源:origin: apache/hive

private void registerDir(Path path, WatchedPathInfo watchedPathInfo) {
 watchedPaths.put(path, watchedPathInfo);
 try {
  WatchKey watchKey = path.register(watchService, ENTRY_CREATE);
  watchedPathInfo.setWatchKey(watchKey);
  watchedPathQueue.add(watchedPathInfo);
  if (watchedPathInfo.type == Type.FINAL) {
   trackWatchForAttempt(watchedPathInfo, watchKey);
  }
 } catch (IOException e) {
  LOG.warn("Unable to setup watch for: " + path);
 }
}

代码示例来源:origin: apache/hive

/**
 * Register a base dir for an application
 * @param pathString the full path including jobId, user - /${local.dir}/appCache/${appId}/userCache/${user}
 * @param appId the appId
 * @param user the user
 * @param expiry when to expire the watch - in ms
 * @throws IOException
 */
void registerDagDir(String pathString, String appId, int dagIdentifier, String user, long expiry) throws IOException {
 // The path string contains the dag Identifier
 Path path = FileSystems.getDefault().getPath(pathString);
 WatchedPathInfo watchedPathInfo =
   new WatchedPathInfo(System.currentTimeMillis() + expiry, Type.BASE, appId, dagIdentifier,
     user);
 watchedPaths.put(path, watchedPathInfo);
 WatchKey watchKey = path.register(watchService, ENTRY_CREATE);
 watchedPathInfo.setWatchKey(watchKey);
 watchedPathQueue.add(watchedPathInfo);
 // TODO Watches on the output dirs need to be cancelled at some point. For now - via the expiry.
}

代码示例来源:origin: rapidoid/rapidoid

private void init(Path dir) {
  Log.debug("Registering directory watch", "dir", dir);
  try {
    WatchKey key = dir.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
    U.notNull(key, "watch key");
    keys.put(key, dir);
  } catch (IOException e) {
    Log.warn("Couldn't register to watch for changes", "dir", dir);
  }
}

代码示例来源:origin: oracle/helidon

private void register() throws IOException {
  Path target = target(path);
  Path dir = parentDir(target);
  WatchKey oldWatchKey = watchKey;
  watchKey = dir.register(watchService,
              CollectionsHelper.listOf(ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY)
                  .toArray(new WatchEvent.Kind[0]),
              watchServiceModifiers.toArray(new WatchEvent.Modifier[0]));
  if (oldWatchKey != null) {
    oldWatchKey.cancel();
  }
}

相关文章