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

@ -348,11 +348,14 @@ public class FileUtils {
} }
public static void deleteFile(String path) { public static void deleteFile(String path) {
if (StringUtils.isNotBlank(path)) {
validateFileName(path);
File file = new File(path); File file = new File(path);
if (file.exists()) { if (file.exists()) {
file.delete(); file.delete();
} }
} }
}
public static void deleteDir(String path) { public static void deleteDir(String path) {
File file = new File(path); File file = new File(path);

View File

@ -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;
} }
} }
} }

View File

@ -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);
} }