From ef5052e7ea67d0741e8a30e97046bbb7952c8e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=B2=BE=E5=8D=8E?= <842761733@qq.com> Date: Thu, 28 Jan 2021 15:42:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Ajodd.io.NetUtil.down?= =?UTF-8?q?loadFile=E4=B8=8B=E8=BD=BD=E5=A4=A7=E4=BA=8E16M=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/keking/utils/DownloadUtils.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/cn/keking/utils/DownloadUtils.java b/server/src/main/java/cn/keking/utils/DownloadUtils.java index 4c9c0350..feae7588 100644 --- a/server/src/main/java/cn/keking/utils/DownloadUtils.java +++ b/server/src/main/java/cn/keking/utils/DownloadUtils.java @@ -4,7 +4,6 @@ import cn.keking.config.ConfigConstants; import cn.keking.model.FileAttribute; import cn.keking.model.ReturnResponse; import io.mola.galimatias.GalimatiasParseException; -import jodd.io.NetUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,8 +37,16 @@ public class DownloadUtils { try { URL url = WebUtils.normalizedURL(urlStr); if (isHttpUrl(url)) { - File realFile = new File(realPath); - NetUtil.downloadFile(url.toString(),realFile); + URLConnection connection = url.openConnection(); + InputStream is = connection.getInputStream(); + FileOutputStream os = new FileOutputStream(realPath); + byte[] buffer = new byte[4 * 1024]; + int read; + while ((read = is.read(buffer)) > 0) { + os.write(buffer, 0, read); + } + os.close(); + is.close(); } else if (isFtpUrl(url)) { String ftpUsername = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_USERNAME); String ftpPassword = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_PASSWORD);