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