mirror of https://github.com/ZhongFuCheng3y/austin
parent
97bbfa954c
commit
7578887b9c
@ -0,0 +1,38 @@
|
||||
package com.java3y.austin.support.utils;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import com.google.common.base.Throwables;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author 3y
|
||||
* @date 2023/2/14
|
||||
*/
|
||||
@Slf4j
|
||||
public class AustinFileUtils {
|
||||
|
||||
/**
|
||||
* 读取 远程链接 返回File对象
|
||||
*
|
||||
* @param path 文件路径
|
||||
* @param remoteUrl cdn/oss文件访问链接
|
||||
* @return
|
||||
*/
|
||||
public static File getRemoteUrl2File(String path, String remoteUrl) {
|
||||
try {
|
||||
new File(path).mkdirs();
|
||||
URL url = new URL(remoteUrl);
|
||||
File file = new File(path, url.getPath());
|
||||
IoUtil.copy(url.openStream(), new FileOutputStream(file));
|
||||
return file;
|
||||
} catch (Exception e) {
|
||||
log.error("AustinFileUtils#getRemoteUrl2File fail:{},remoteUrl:{}", Throwables.getStackTraceAsString(e), remoteUrl);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue