|
|
@ -33,7 +33,6 @@ public class AustinFileUtils {
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static File getRemoteUrl2File(String path, String remoteUrl) {
|
|
|
|
public static File getRemoteUrl2File(String path, String remoteUrl) {
|
|
|
|
|
|
|
|
|
|
|
|
InputStream inputStream = null;
|
|
|
|
InputStream inputStream = null;
|
|
|
|
FileOutputStream fileOutputStream = null;
|
|
|
|
FileOutputStream fileOutputStream = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -41,7 +40,11 @@ public class AustinFileUtils {
|
|
|
|
File file = new File(path, url.getPath());
|
|
|
|
File file = new File(path, url.getPath());
|
|
|
|
inputStream = url.openStream();
|
|
|
|
inputStream = url.openStream();
|
|
|
|
if (!file.exists()) {
|
|
|
|
if (!file.exists()) {
|
|
|
|
file.getParentFile().mkdirs();
|
|
|
|
boolean res = file.getParentFile().mkdirs();
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
|
|
|
|
log.error("AustinFileUtils#getRemoteUrl2File Failed to create folder, path:{}, remoteUrl:{}", path, remoteUrl);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
fileOutputStream = new FileOutputStream(file);
|
|
|
|
fileOutputStream = new FileOutputStream(file);
|
|
|
|
IoUtil.copy(inputStream, fileOutputStream);
|
|
|
|
IoUtil.copy(inputStream, fileOutputStream);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -49,20 +52,8 @@ public class AustinFileUtils {
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("AustinFileUtils#getRemoteUrl2File fail:{},remoteUrl:{}", Throwables.getStackTraceAsString(e), remoteUrl);
|
|
|
|
log.error("AustinFileUtils#getRemoteUrl2File fail:{},remoteUrl:{}", Throwables.getStackTraceAsString(e), remoteUrl);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (Objects.nonNull(inputStream)) {
|
|
|
|
closeQuietly(inputStream);
|
|
|
|
try {
|
|
|
|
closeQuietly(fileOutputStream);
|
|
|
|
inputStream.close();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
log.error("close#inputStream fail:{}", Throwables.getStackTraceAsString(e));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Objects.nonNull(fileOutputStream)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
fileOutputStream.close();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
log.error("close#fileOutputStream fail:{}", Throwables.getStackTraceAsString(e));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -85,4 +76,33 @@ public class AustinFileUtils {
|
|
|
|
return files;
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 关闭InputStream流
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param inputStream
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static void closeQuietly(InputStream inputStream) {
|
|
|
|
|
|
|
|
if (Objects.nonNull(inputStream)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
inputStream.close();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
log.error("close#inputStream fail:{}", Throwables.getStackTraceAsString(e));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 关闭FileOutputStream流
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param fileOutputStream
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static void closeQuietly(FileOutputStream fileOutputStream) {
|
|
|
|
|
|
|
|
if (Objects.nonNull(fileOutputStream)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
fileOutputStream.close();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
log.error("close#fileOutputStream fail:{}", Throwables.getStackTraceAsString(e));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|