Commit 679d3733 by 朱亚洁

feat:[none]文件名支持句号

parent ac5a0b45
......@@ -1124,4 +1124,26 @@ public class FileUtils {
return outStream.toByteArray();
}
/**
* 格式化文件名称,过滤特殊字符(名称太长进行截断)
* 针对压缩包内文件名称, 支持.
* @param fileName
*/
public static String formatName4Zip(String fileName) {
if (StringUtil.isEmpty(fileName)) {
return null;
}
try {
String regEx = "[*/\\\\:?\"<|>\\s+%#&=()]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(fileName);
String result = m.replaceAll("").trim();
// 文件名称过长的话,限制40个字
return result.length() > 40 ? result.substring(0, 40) : result;
} catch (Exception e) {
LOGGER.error("【文件API】格式化文件名称.[formatName]:" + e.getMessage(), e);
return UUIDUitl.taskName();
}
}
}
......@@ -188,7 +188,7 @@ public class CompressUtils {
int idx = 1;
for (String[] files : fileUrlList) {
String fileType = FileUtils.getFileType(files[1]);
String fileName = FileUtils.formatName(files[0]);
String fileName = FileUtils.formatName4Zip(files[0]);
String downloadLocalPath = downloadPath + "/" + fileName + "_" + idx + "." + fileType;
FileUtils.downloadFileFromUrl(files[1], downloadLocalPath);
idx++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment