简化下载文件 io 操作
parent
212526d989
commit
d95fbe02bd
|
@ -4,6 +4,7 @@ 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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -37,16 +38,8 @@ public class DownloadUtils {
|
|||
try {
|
||||
URL url = WebUtils.normalizedURL(urlStr);
|
||||
if (isHttpUrl(url)) {
|
||||
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();
|
||||
File realFile = new File(realPath);
|
||||
FileUtils.copyURLToFile(url,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);
|
||||
|
|
Loading…
Reference in New Issue