fix: 公共文件处理调整

Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2023-10-09 10:34:49 +08:00 committed by fit2-zhao
parent f6c4c989cc
commit 7eb6322a7e
3 changed files with 15 additions and 12 deletions

View File

@ -235,8 +235,8 @@ public class FileUtils {
}
public static void moveFileToDir(String filePath, String targetPath) {
copyFileToDir(filePath, targetPath);
deleteFile(filePath);
copyFileToDir(filePath, targetPath);
deleteFile(filePath);
}
private static void copyFileToDir(File file, File targetDir) {
@ -348,9 +348,12 @@ public class FileUtils {
}
public static void deleteFile(String path) {
File file = new File(path);
if (file.exists()) {
file.delete();
if (StringUtils.isNotBlank(path)) {
validateFileName(path);
File file = new File(path);
if (file.exists()) {
file.delete();
}
}
}

View File

@ -161,9 +161,9 @@ public class CommandService {
}
}
public boolean checkKeyStore(String password, String path) {
public void checkKeyStore(String password, String path) {
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();
try (BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
String line = null;
@ -176,11 +176,9 @@ public class CommandService {
}
}
}
return true;
} catch (Exception e) {
LogUtil.error(e);
MSException.throwException(e.getMessage());
return false;
}
}
}

View File

@ -36,7 +36,8 @@ public class FileUtil {
*/
public static File multipartFileToFile(MultipartFile file) {
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());
inputStreamToFile(ins, toFile);
return toFile;
@ -49,17 +50,18 @@ public class FileUtil {
/**
* File MultipartFile
*
* @param file
* @return
*/
public static MultipartFile fileToMultipartFile(File file) {
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 {
OutputStream os = item.getOutputStream();
os.write(FileUtils.fileToByte(file));
} catch (IOException e) {
e.printStackTrace();
LogUtil.error(e);
}
return new CommonsMultipartFile(item);
}