當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。