本文整理了Java中java.nio.file.WatchService.take()
方法的一些代码示例,展示了WatchService.take()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WatchService.take()
方法的具体详情如下:
包路径:java.nio.file.WatchService
类名称:WatchService
方法名:take
暂无
代码示例来源:origin: syncany/syncany
@Override
protected boolean pollEvents() throws InterruptedException {
// Take events, but don't care what they are!
WatchKey watchKey = watchService.take();
watchKey.pollEvents();
watchKey.reset();
// Events are always relevant; ignored paths are not monitored
return true;
}
代码示例来源:origin: lets-blade/blade
public void processEvent(BiConsumer<WatchEvent.Kind<Path>, Path> processor){
for(;;){
WatchKey key;
try{
key = watcher.take();
}catch (InterruptedException e) {
return;
}
Path dir = pathMap.get(key);
for (WatchEvent<?> event: key.pollEvents()){
WatchEvent.Kind kind = event.kind();
Path filePath = dir.resolve(((WatchEvent<Path>)event).context());
if(Files.isDirectory(filePath)) continue;
log.info("File {} changes detected!",filePath.toString());
//copy updated files to target
processor.accept(kind, filePath);
}
key.reset();
}
}
代码示例来源:origin: lets-blade/blade
public void processEvent(BiConsumer<WatchEvent.Kind<Path>, Path> processor){
for(;;){
WatchKey key;
try{
key = watcher.take();
}catch (InterruptedException e) {
return;
}
Path dir = pathMap.get(key);
for (WatchEvent<?> event: key.pollEvents()){
WatchEvent.Kind kind = event.kind();
Path filePath = dir.resolve(((WatchEvent<Path>)event).context());
if(Files.isDirectory(filePath)) continue;
log.info("File {} changes detected!",filePath.toString());
//copy updated files to target
processor.accept(kind, filePath);
}
key.reset();
}
}
代码示例来源:origin: konsoletyper/teavm
private void take() throws InterruptedException, IOException {
while (true) {
WatchKey key = watchService.take();
if (key != null && filter(key)) {
return;
}
}
}
代码示例来源: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: dreamhead/moco
private void loop() {
try {
WatchKey key = service.take();
Collection<Path> paths = keys.get(key);
for (WatchEvent<?> event : from(key.pollEvents()).filter(isModifyEvent())) {
final Path context = (Path) event.context();
for (Path path : from(paths).filter(isForPath(context))) {
for (Function<File, Void> listener : this.listeners.get(path)) {
listener.apply(path.toFile());
}
break;
}
}
key.reset();
} catch (ClosedWatchServiceException ignored) {
} catch (InterruptedException e) {
logger.error("Error happens", e);
}
}
代码示例来源:origin: neo4j/neo4j
private void prepareWatcher( TestWatchKey watchKey ) throws InterruptedException
{
when( watchServiceMock.take() ).thenReturn( watchKey )
.thenThrow( InterruptedException.class );
}
代码示例来源:origin: apache/zookeeper
WatchKey key;
try {
key = watchService.take();
} catch (InterruptedException|ClosedWatchServiceException e) {
if (LOG.isDebugEnabled()) {
代码示例来源:origin: neo4j/neo4j
@Override
public void startWatching() throws InterruptedException
{
watch = true;
while ( watch )
{
WatchKey key = watchService.take();
if ( key != null )
{
List<WatchEvent<?>> watchEvents = key.pollEvents();
for ( WatchEvent<?> watchEvent : watchEvents )
{
WatchEvent.Kind<?> kind = watchEvent.kind();
if ( StandardWatchEventKinds.ENTRY_MODIFY == kind )
{
notifyAboutModification( watchEvent );
}
if ( StandardWatchEventKinds.ENTRY_DELETE == kind )
{
notifyAboutDeletion( watchEvent );
}
}
key.reset();
}
}
}
代码示例来源:origin: jersey/jersey
final WatchKey watchKey = watcher.take();
代码示例来源:origin: oracle/helidon
WatchKey key;
try {
key = watchService.take();
} catch (Exception ie) {
fail = true;
代码示例来源:origin: lets-blade/blade
final WatchKey key = watchService.take();
for (WatchEvent<?> watchEvent : key.pollEvents()) {
final WatchEvent.Kind<?> kind = watchEvent.kind();
代码示例来源:origin: lets-blade/blade
final WatchKey key = watchService.take();
for (WatchEvent<?> watchEvent : key.pollEvents()) {
final WatchEvent.Kind<?> kind = watchEvent.kind();
代码示例来源:origin: oracle/opengrok
final WatchKey key;
try {
key = watchDogWatcher.take();
} catch (ClosedWatchServiceException x) {
break;
代码示例来源:origin: jooby-project/jooby
@Override
public void run() {
// register directory:
for (FileEventOptions options : optionList) {
log.debug("watching: {}", options);
try {
registerTree(options.path(), options);
} catch (IOException x) {
log.error("traversal of {} resulted in exception", options.path(), x);
}
}
boolean process = true;
while (process) {
try {
process = poll(watcher.take());
} catch (InterruptedException x) {
Thread.currentThread().interrupt();
process = false;
}
}
}
代码示例来源:origin: rapidoid/rapidoid
key = watchService.take();
代码示例来源:origin: looly/hutool
WatchKey wk;
try {
wk = watchService.take();
} catch (InterruptedException e) {
代码示例来源:origin: looly/hutool
WatchKey wk;
try {
wk = watchService.take();
} catch (InterruptedException e) {
代码示例来源:origin: org.apache.logging.log4j/log4j-core
key = watcher.take();
代码示例来源:origin: org.apache.logging.log4j/log4j-core
key = watcher.take();
内容来源于网络,如有侵权,请联系作者删除!