This commit is contained in:
Looly
2020-08-02 20:53:03 +08:00
parent 0dcf4f9aca
commit 951d06d90f

View File

@@ -15,7 +15,6 @@ import java.nio.file.FileVisitResult;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor; import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent; import java.nio.file.WatchEvent;
import java.nio.file.WatchKey; import java.nio.file.WatchKey;
import java.nio.file.WatchService; import java.nio.file.WatchService;
@@ -139,6 +138,7 @@ public class WatchServer extends Thread implements Closeable, Serializable {
wk = watchService.take(); wk = watchService.take();
} catch (InterruptedException | ClosedWatchServiceException e) { } catch (InterruptedException | ClosedWatchServiceException e) {
// 用户中断 // 用户中断
close();
return; return;
} }
@@ -152,6 +152,7 @@ public class WatchServer extends Thread implements Closeable, Serializable {
action.doAction(event, currentPath); action.doAction(event, currentPath);
} }
wk.reset(); wk.reset();
} }
@@ -163,15 +164,15 @@ public class WatchServer extends Thread implements Closeable, Serializable {
*/ */
public void watch(Watcher watcher, Filter<WatchEvent<?>> watchFilter) { public void watch(Watcher watcher, Filter<WatchEvent<?>> watchFilter) {
watch((event, currentPath)->{ watch((event, currentPath)->{
WatchEvent.Kind<?> kind = event.kind(); final WatchEvent.Kind<?> kind = event.kind();
if (kind == StandardWatchEventKinds.ENTRY_CREATE) { if (kind == WatchKind.CREATE.getValue()) {
watcher.onCreate(event, currentPath); watcher.onCreate(event, currentPath);
} else if (kind == StandardWatchEventKinds.ENTRY_MODIFY) { } else if (kind == WatchKind.MODIFY.getValue()) {
watcher.onModify(event, currentPath); watcher.onModify(event, currentPath);
} else if (kind == StandardWatchEventKinds.ENTRY_DELETE) { } else if (kind == WatchKind.DELETE.getValue()) {
watcher.onDelete(event, currentPath); watcher.onDelete(event, currentPath);
} else if (kind == StandardWatchEventKinds.OVERFLOW) { } else if (kind == WatchKind.OVERFLOW.getValue()) {
watcher.onOverflow(event, currentPath); watcher.onOverflow(event, currentPath);
} }
}, watchFilter); }, watchFilter);