mirror of https://github.com/deavmi/JavaOCP
Compare commits
3 Commits
71b5a13f9c
...
e188f4cb58
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | e188f4cb58 | |
Tristan B. Velloza Kildaire | 3cc2b32d54 | |
Tristan B. Velloza Kildaire | 7a7cf62546 |
|
@ -17,6 +17,7 @@ import java.nio.file.attribute.UserPrincipal;
|
|||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
|
@ -112,7 +113,13 @@ public class App
|
|||
* I sleep here to give me time to modify an directory
|
||||
* entry in /home/deavmi
|
||||
*/
|
||||
Thread.sleep(5000);
|
||||
// Thread.sleep(5000);
|
||||
|
||||
/**
|
||||
* Alternatively you can call {@link WatchService}'s
|
||||
* <code>take()</code> method which blocks till an event
|
||||
*/
|
||||
eventHandle = watcher.take();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -133,10 +140,17 @@ public class App
|
|||
*/
|
||||
if(event.kind() == StandardWatchEventKinds.ENTRY_MODIFY)
|
||||
{
|
||||
System.out.println("Modified path: "+((Path)event.context()).toAbsolutePath());
|
||||
System.out.println("Modified path: "+(path1.resolve((Path)event.context())));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Because we called <code>take()</code> on the {@link WatchService}
|
||||
* it has removed it and it won't be watched (the directory the key
|
||||
* is registered for) until we call <code>reset()</code> below
|
||||
* which places it back into the watcher for watching.
|
||||
*/
|
||||
eventHandle.reset();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -195,6 +209,5 @@ public class App
|
|||
|
||||
UserPrincipal user = Files.getOwner(resolvedPath, LinkOption.NOFOLLOW_LINKS);
|
||||
System.out.println("The owner is: '"+user+"'");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue