[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [flux-dev] Status update
|
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class App {
public static void main(String[] args) throws InterruptedException, IOException {
Path path = Paths.get(args[0]);
WatchService ew = FileSystems.getDefault().newWatchService();
WatchService wc = path.getFileSystem().newWatchService();
path.register(wc, StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE);
while (true) {
WatchKey key = wc.poll(20, TimeUnit.SECONDS);
if (key == null) {
continue;
}
List<WatchEvent<?>> list = key.pollEvents();
for (WatchEvent<?> w1 : list) {
switch (w1.kind().name()) {
case "ENTRY_CREATE":
System.out.println(w1.context() + " " + w1.kind());
break;
case "ENTRY_DELETE":
System.out.println(w1.context() + " " + w1.kind());
break;
case "ENTRY_MODIFY":
System.out.println(w1.context() + " " + w1.kind());
break;
}
}
key.reset();
}
}
}