From c68b9df0dfb131bb3e5a243abe75ac5b50663f5e Mon Sep 17 00:00:00 2001 From: Looly Date: Fri, 29 Dec 2023 00:19:48 +0800 Subject: [PATCH] =?UTF-8?q?WatchServer=E6=96=B0=E5=A2=9E=E9=80=9A=E8=BF=87?= =?UTF-8?q?Path=E8=8E=B7=E5=8F=96WatchKey=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++- .../cn/hutool/core/io/WatchMonitorTest.java | 35 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 901fa845b..aef8b83ce 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,11 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.25(2023-12-28) +# 5.8.25(2023-12-29) ### 🐣新特性 +* 【core 】 WatchServer新增通过Path获取WatchKey方法(pr#1145@Gitee) + ### 🐞Bug修复 * 【core 】 修复StrJoin当append内容后调用length()会出现空指针问题(issue#3444@Github) * 【core 】 修复PostgreSQL、H2使用upsert字段大小写问题(issue#I8PB4X@Gitee) diff --git a/hutool-core/src/test/java/cn/hutool/core/io/WatchMonitorTest.java b/hutool-core/src/test/java/cn/hutool/core/io/WatchMonitorTest.java index 7769088ff..631bf060c 100755 --- a/hutool-core/src/test/java/cn/hutool/core/io/WatchMonitorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/WatchMonitorTest.java @@ -1,17 +1,17 @@ package cn.hutool.core.io; -import java.nio.file.Path; -import java.nio.file.WatchEvent; -import java.nio.file.WatchKey; -import java.nio.file.Watchable; - import cn.hutool.core.io.watch.SimpleWatcher; import cn.hutool.core.io.watch.WatchMonitor; import cn.hutool.core.io.watch.Watcher; import cn.hutool.core.io.watch.watchers.DelayWatcher; import cn.hutool.core.lang.Console; +import org.junit.Ignore; import org.junit.Test; +import java.nio.file.Path; +import java.nio.file.WatchEvent; +import java.nio.file.WatchKey; + /** * 文件监听单元测试 * @@ -21,36 +21,37 @@ public class WatchMonitorTest { WatchMonitor monitor; Watcher watcher = new SimpleWatcher() { @Override - public void onCreate(WatchEvent event, Path currentPath) { - Object obj = event.context(); + public void onCreate(final WatchEvent event, final Path currentPath) { + final Object obj = event.context(); Console.log("创建:{}-> {}", currentPath, obj); - WatchKey watchKey = monitor.getWatchKey(currentPath); - Path watchable = (Path) watchKey.watchable(); - Path fullPath = watchable.resolve((Path) event.context()); + final WatchKey watchKey = monitor.getWatchKey(currentPath); + final Path watchable = (Path) watchKey.watchable(); + final Path fullPath = watchable.resolve((Path) event.context()); Console.log("Path 完整对象:{}", fullPath); } @Override - public void onModify(WatchEvent event, Path currentPath) { - Object obj = event.context(); + public void onModify(final WatchEvent event, final Path currentPath) { + final Object obj = event.context(); Console.log("修改:{}-> {}", currentPath, obj); } @Override - public void onDelete(WatchEvent event, Path currentPath) { - Object obj = event.context(); + public void onDelete(final WatchEvent event, final Path currentPath) { + final Object obj = event.context(); Console.log("删除:{}-> {}", currentPath, obj); } @Override - public void onOverflow(WatchEvent event, Path currentPath) { - Object obj = event.context(); + public void onOverflow(final WatchEvent event, final Path currentPath) { + final Object obj = event.context(); Console.log("Overflow:{}-> {}", currentPath, obj); } }; @Test + @Ignore public void testFile() { monitor = WatchMonitor.createAll("d:/test/aaa.txt", new DelayWatcher(watcher, 500)); @@ -60,9 +61,9 @@ public class WatchMonitorTest { } @Test + @Ignore public void testDir() { monitor = WatchMonitor.createAll("d:/", new DelayWatcher(watcher, 500)); - monitor.run(); }