fix: 公共文件处理调整
Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
parent
f6c4c989cc
commit
7eb6322a7e
|
@ -235,8 +235,8 @@ public class FileUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void moveFileToDir(String filePath, String targetPath) {
|
public static void moveFileToDir(String filePath, String targetPath) {
|
||||||
copyFileToDir(filePath, targetPath);
|
copyFileToDir(filePath, targetPath);
|
||||||
deleteFile(filePath);
|
deleteFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copyFileToDir(File file, File targetDir) {
|
private static void copyFileToDir(File file, File targetDir) {
|
||||||
|
@ -348,9 +348,12 @@ public class FileUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteFile(String path) {
|
public static void deleteFile(String path) {
|
||||||
File file = new File(path);
|
if (StringUtils.isNotBlank(path)) {
|
||||||
if (file.exists()) {
|
validateFileName(path);
|
||||||
file.delete();
|
File file = new File(path);
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,9 +161,9 @@ public class CommandService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkKeyStore(String password, String path) {
|
public void checkKeyStore(String password, String path) {
|
||||||
try {
|
try {
|
||||||
String keytoolArgs[] = {"keytool", "-rfc", "-list", "-keystore", path, "-storepass", password};
|
String[] keytoolArgs = {"keytool", "-rfc", "-list", "-keystore", path, "-storepass", password};
|
||||||
Process p = new ProcessBuilder(keytoolArgs).start();
|
Process p = new ProcessBuilder(keytoolArgs).start();
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
|
||||||
String line = null;
|
String line = null;
|
||||||
|
@ -176,11 +176,9 @@ public class CommandService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
MSException.throwException(e.getMessage());
|
MSException.throwException(e.getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,8 @@ public class FileUtil {
|
||||||
*/
|
*/
|
||||||
public static File multipartFileToFile(MultipartFile file) {
|
public static File multipartFileToFile(MultipartFile file) {
|
||||||
if (file != null && file.getSize() > 0) {
|
if (file != null && file.getSize() > 0) {
|
||||||
try (InputStream ins = file.getInputStream();) {
|
try (InputStream ins = file.getInputStream()) {
|
||||||
|
FileUtils.validateFileName(file.getOriginalFilename());
|
||||||
File toFile = new File(file.getOriginalFilename());
|
File toFile = new File(file.getOriginalFilename());
|
||||||
inputStreamToFile(ins, toFile);
|
inputStreamToFile(ins, toFile);
|
||||||
return toFile;
|
return toFile;
|
||||||
|
@ -49,17 +50,18 @@ public class FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File 转 MultipartFile
|
* File 转 MultipartFile
|
||||||
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static MultipartFile fileToMultipartFile(File file) {
|
public static MultipartFile fileToMultipartFile(File file) {
|
||||||
DiskFileItem item = new DiskFileItem("file", MediaType.MULTIPART_FORM_DATA_VALUE, true,
|
DiskFileItem item = new DiskFileItem("file", MediaType.MULTIPART_FORM_DATA_VALUE, true,
|
||||||
file.getName(), (int)file.length(), file.getParentFile());
|
file.getName(), (int) file.length(), file.getParentFile());
|
||||||
try {
|
try {
|
||||||
OutputStream os = item.getOutputStream();
|
OutputStream os = item.getOutputStream();
|
||||||
os.write(FileUtils.fileToByte(file));
|
os.write(FileUtils.fileToByte(file));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
LogUtil.error(e);
|
||||||
}
|
}
|
||||||
return new CommonsMultipartFile(item);
|
return new CommonsMultipartFile(item);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue