mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
新增 文件监听 WatchServer 新增通过 Path 获取 WatchKey 方法
This commit is contained in:
parent
674c601f86
commit
95f37beb66
@ -3,6 +3,7 @@ package cn.hutool.core.io.watch;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Filter;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@ -178,6 +179,21 @@ public class WatchServer extends Thread implements Closeable, Serializable {
|
||||
}, watchFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 path 获取 watchKey
|
||||
*
|
||||
* @param path path
|
||||
* @return 如果不存在则返回 null
|
||||
*/
|
||||
public WatchKey getWatchKey(Path path) {
|
||||
for (Map.Entry<WatchKey, Path> entry : watchKeyPathMap.entrySet()) {
|
||||
if (ObjectUtil.equals(path, entry.getValue())) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭监听
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user