From 374c06472f373bcfc92d877b79bc3d5caf607418 Mon Sep 17 00:00:00 2001
From: chenkailing <632104866@qq.com>
Date: Sat, 9 Jan 2021 15:38:21 +0800
Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20apache-commons-io=20?=
=?UTF-8?q?=E5=8C=85=E4=BE=9D=E8=B5=96=EF=BC=8C=E9=87=87=E7=94=A8jodd?=
=?UTF-8?q?=E7=9A=84io=E5=B7=A5=E5=85=B7=E6=9B=BF=E4=BB=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
server/pom.xml | 5 -----
.../java/cn/keking/service/impl/SimTextFilePreviewImpl.java | 4 ++--
server/src/main/java/cn/keking/utils/DownloadUtils.java | 5 +++--
.../cn/keking/web/controller/OnlinePreviewController.java | 5 +++--
4 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/server/pom.xml b/server/pom.xml
index 064ff85e..60808d7d 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -105,11 +105,6 @@
fr.opensagres.xdocreport.document
1.0.5
-
- commons-io
- commons-io
- 2.4
-
org.apache.commons
diff --git a/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
index 95156e85..2a2751cf 100644
--- a/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
+++ b/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
@@ -5,8 +5,8 @@ import cn.keking.model.ReturnResponse;
import cn.keking.service.FilePreview;
import cn.keking.utils.DownloadUtils;
import cn.keking.utils.KkFileUtils;
+import jodd.io.FileUtil;
import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
@@ -36,7 +36,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
try {
File originFile = new File(response.getContent());
String charset = KkFileUtils.getFileEncode(originFile);
- String fileData = FileUtils.readFileToString(originFile, charset);
+ String fileData = FileUtil.readString(originFile, charset);
model.addAttribute("textData", Base64.encodeBase64String(fileData.getBytes()));
} catch (IOException e) {
return otherFilePreview.notSupportedFile(model, fileAttribute, e.getLocalizedMessage());
diff --git a/server/src/main/java/cn/keking/utils/DownloadUtils.java b/server/src/main/java/cn/keking/utils/DownloadUtils.java
index 76f03c50..1ba05cff 100644
--- a/server/src/main/java/cn/keking/utils/DownloadUtils.java
+++ b/server/src/main/java/cn/keking/utils/DownloadUtils.java
@@ -4,7 +4,8 @@ import cn.keking.config.ConfigConstants;
import cn.keking.model.FileAttribute;
import cn.keking.model.ReturnResponse;
import io.mola.galimatias.GalimatiasParseException;
-import org.apache.commons.io.FileUtils;
+import jodd.io.FileUtil;
+import jodd.io.NetUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,7 +40,7 @@ public class DownloadUtils {
URL url = WebUtils.normalizedURL(urlStr);
if (isHttpUrl(url)) {
File realFile = new File(realPath);
- FileUtils.copyURLToFile(url, realFile);
+ NetUtil.downloadFile(url.toString(),realFile);
} else if (isFtpUrl(url)) {
String ftpUsername = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_USERNAME);
String ftpPassword = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_PASSWORD);
diff --git a/server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java b/server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java
index c11cc406..5d6c644d 100644
--- a/server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java
+++ b/server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java
@@ -8,9 +8,10 @@ import cn.keking.service.cache.CacheService;
import cn.keking.service.impl.OtherFilePreviewImpl;
import cn.keking.service.FileHandlerService;
import cn.keking.utils.WebUtils;
+import fr.opensagres.xdocreport.core.io.IOUtils;
import io.mola.galimatias.GalimatiasParseException;
+import jodd.io.NetUtil;
import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
@@ -103,7 +104,7 @@ public class OnlinePreviewController {
logger.info("下载跨域pdf文件url:{}", urlPath);
try {
URL url = WebUtils.normalizedURL(urlPath);
- byte[] bytes = IOUtils.toByteArray(url);
+ byte[] bytes = NetUtil.downloadBytes(url.toString());
IOUtils.write(bytes, response.getOutputStream());
} catch (IOException | GalimatiasParseException e) {
logger.error("下载跨域pdf文件异常,url:{}", urlPath, e);