[issue/4672]方法造成的文件被占用,注释掉此方法tomcat就能自动清理掉临时文件 ]

pull/4819/head
zhangdaiscott 2023-04-05 11:45:10 +08:00
parent 42589cd1dc
commit ebcddad130
1 changed files with 19 additions and 5 deletions

View File

@ -1,19 +1,19 @@
package org.jeecg.common.util.filter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @Description:
* @author: lsq
* @date: 20210809 15:29
*/
@Slf4j
public class FileTypeFilter {
/**文件后缀*/
@ -112,8 +112,9 @@ public class FileTypeFilter {
*/
private static String getFileType(MultipartFile file) throws Exception {
//update-begin-author:liusq date:20230404 for: [issue/4672]方法造成的文件被占用注释掉此方法tomcat就能自动清理掉临时文件
String fileExtendName = null;
InputStream is;
InputStream is = null;
try {
//is = new FileInputStream(file);
is = file.getInputStream();
@ -130,16 +131,29 @@ public class FileTypeFilter {
break;
}
}
log.info("-----获取到的指定文件类型------"+fileExtendName);
// 如果不是上述类型,则判断扩展名
if (StringUtils.isBlank(fileExtendName)) {
String fileName = file.getOriginalFilename();
// 如果无扩展名,则直接返回空串
if (-1 == fileName.indexOf(".")) {
return "";
}
// 如果有扩展名,则返回扩展名
return getFileTypeBySuffix(fileName);
}
log.info("-----最終的文件类型------"+fileExtendName);
is.close();
return fileExtendName;
} catch (Exception exception) {
throw new Exception(exception.getMessage(), exception);
} catch (Exception e) {
log.error(e.getMessage(), e);
return "";
}finally {
if (is != null) {
is.close();
}
}
//update-end-author:liusq date:20230404 for: [issue/4672]方法造成的文件被占用注释掉此方法tomcat就能自动清理掉临时文件
}
/**