Commit d95fbe02 authored by kl's avatar kl

简化下载文件 io 操作

parent 212526d9
...@@ -4,6 +4,7 @@ import cn.keking.config.ConfigConstants; ...@@ -4,6 +4,7 @@ import cn.keking.config.ConfigConstants;
import cn.keking.model.FileAttribute; import cn.keking.model.FileAttribute;
import cn.keking.model.ReturnResponse; import cn.keking.model.ReturnResponse;
import io.mola.galimatias.GalimatiasParseException; import io.mola.galimatias.GalimatiasParseException;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -37,16 +38,8 @@ public class DownloadUtils { ...@@ -37,16 +38,8 @@ public class DownloadUtils {
try { try {
URL url = WebUtils.normalizedURL(urlStr); URL url = WebUtils.normalizedURL(urlStr);
if (isHttpUrl(url)) { if (isHttpUrl(url)) {
URLConnection connection = url.openConnection(); File realFile = new File(realPath);
InputStream is = connection.getInputStream(); FileUtils.copyURLToFile(url,realFile);
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)) { } else if (isFtpUrl(url)) {
String ftpUsername = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_USERNAME); String ftpUsername = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_USERNAME);
String ftpPassword = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_PASSWORD); String ftpPassword = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_PASSWORD);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment