浏览代码

增加ByteArray初始化方法,支持输入URL并自动下载

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi 3 年之前
父节点
当前提交
6369b7f25a
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      tools-common/src/main/java/com/qmth/boot/tools/models/ByteArray.java

+ 11 - 0
tools-common/src/main/java/com/qmth/boot/tools/models/ByteArray.java

@@ -4,6 +4,7 @@ import com.qmth.boot.tools.codec.CodecUtils;
 import com.qmth.boot.tools.io.IOUtils;
 
 import java.io.*;
+import java.net.URL;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 
@@ -27,6 +28,16 @@ public class ByteArray {
         return value;
     }
 
+    /**
+     * 根据URL初始化
+     *
+     * @param url
+     * @return
+     */
+    public static ByteArray fromUrl(String url) throws IOException {
+        return ByteArray.fromInputStream(new URL(url).openStream());
+    }
+
     /**
      * 根据输入流初始化
      *