Looly 5 年 前
コミット
942521862d

+ 1 - 0
CHANGELOG.md

@@ -28,6 +28,7 @@
 * 【extra  】     修复模板中无效引用的问题
 * 【extra  】     修复读取JSON文本配置未应用到子对象的问题(issue#818@Github)
 * 【extra  】     修复XmlUtil.createXml中namespace反向问题
+* 【core   】     修复WatchMonitor默认无event问题
 
 -------------------------------------------------------------------------------------------------------------
 

+ 10 - 0
hutool-core/src/main/java/cn/hutool/core/io/watch/WatchKind.java

@@ -35,6 +35,16 @@ public enum WatchKind {
 	 */
 	DELETE(StandardWatchEventKinds.ENTRY_DELETE);
 
+	/**
+	 * 全部事件
+	 */
+	public static final WatchEvent.Kind<?>[] ALL = {//
+			OVERFLOW.getValue(),      //事件丢失
+			MODIFY.getValue(), //修改
+			CREATE.getValue(),  //创建
+			DELETE.getValue()   //删除
+	};
+
 	private WatchEvent.Kind<?> value;
 
 	/**

+ 5 - 11
hutool-core/src/main/java/cn/hutool/core/io/watch/WatchMonitor.java

@@ -15,7 +15,6 @@ import java.nio.file.Files;
 import java.nio.file.LinkOption;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.nio.file.StandardWatchEventKinds;
 import java.nio.file.WatchEvent;
 import java.nio.file.WatchService;
 
@@ -35,28 +34,23 @@ public class WatchMonitor extends WatchServer {
 	/**
 	 * 事件丢失
 	 */
-	public static final WatchEvent.Kind<?> OVERFLOW = StandardWatchEventKinds.OVERFLOW;
+	public static final WatchEvent.Kind<?> OVERFLOW = WatchKind.OVERFLOW.getValue();
 	/**
 	 * 修改事件
 	 */
-	public static final WatchEvent.Kind<?> ENTRY_MODIFY = StandardWatchEventKinds.ENTRY_MODIFY;
+	public static final WatchEvent.Kind<?> ENTRY_MODIFY = WatchKind.MODIFY.getValue();
 	/**
 	 * 创建事件
 	 */
-	public static final WatchEvent.Kind<?> ENTRY_CREATE = StandardWatchEventKinds.ENTRY_CREATE;
+	public static final WatchEvent.Kind<?> ENTRY_CREATE = WatchKind.CREATE.getValue();
 	/**
 	 * 删除事件
 	 */
-	public static final WatchEvent.Kind<?> ENTRY_DELETE = StandardWatchEventKinds.ENTRY_DELETE;
+	public static final WatchEvent.Kind<?> ENTRY_DELETE = WatchKind.DELETE.getValue();
 	/**
 	 * 全部事件
 	 */
-	public static final WatchEvent.Kind<?>[] EVENTS_ALL = {//
-			OVERFLOW,      //事件丢失
-			ENTRY_MODIFY, //修改
-			ENTRY_CREATE,  //创建
-			ENTRY_DELETE   //删除
-	};
+	public static final WatchEvent.Kind<?>[] EVENTS_ALL = WatchKind.ALL;
 
 	/**
 	 * 监听路径,必须为目录

+ 4 - 2
hutool-core/src/main/java/cn/hutool/core/io/watch/WatchServer.java

@@ -95,12 +95,14 @@ public class WatchServer extends Thread implements Closeable, Serializable {
 	 * @param maxDepth 递归下层目录的最大深度
 	 */
 	public void registerPath(Path path, int maxDepth) {
+		final WatchEvent.Kind<?>[] kinds = ArrayUtil.defaultIfEmpty(this.events, WatchKind.ALL);
+
 		try {
 			final WatchKey key;
 			if (ArrayUtil.isEmpty(this.modifiers)) {
-				key = path.register(this.watchService, this.events);
+				key = path.register(this.watchService, kinds);
 			} else {
-				key = path.register(this.watchService, this.events, this.modifiers);
+				key = path.register(this.watchService, kinds, this.modifiers);
 			}
 			watchKeyPathMap.put(key, path);
 

+ 4 - 1
hutool-http/src/main/java/cn/hutool/http/server/HttpServerResponse.java

@@ -255,7 +255,8 @@ public class HttpServerResponse extends HttpServerBase {
 	/**
 	 * 写出数据到客户端
 	 *
-	 * @param data 数据
+	 * @param data        数据
+	 * @param contentType Content-Type类型
 	 * @return this
 	 */
 	public HttpServerResponse write(String data, String contentType) {
@@ -301,6 +302,7 @@ public class HttpServerResponse extends HttpServerBase {
 	 *
 	 * @param in          需要返回客户端的内容
 	 * @param contentType 返回的类型
+	 * @return this
 	 * @since 5.2.6
 	 */
 	public HttpServerResponse write(InputStream in, String contentType) {
@@ -330,6 +332,7 @@ public class HttpServerResponse extends HttpServerBase {
 	 * 返回文件给客户端(文件下载)
 	 *
 	 * @param file 写出的文件对象
+	 * @return this
 	 * @since 5.2.6
 	 */
 	public HttpServerResponse write(File file) {