ZipUtil.unzip增加编码容错(issue#I3UZ28@Gitee)

This commit is contained in:
Looly 2024-11-13 12:35:59 +08:00
parent 0ba6c8ecda
commit 4a860c77ff
2 changed files with 14 additions and 5 deletions

View File

@ -2,10 +2,11 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.34(2024-11-12)
# 5.8.34(2024-11-13)
### 🐣新特性
* 【http 】 增加Windows微信浏览器识别issue#IB3SJF@Gitee
* 【core 】 ZipUtil.unzip增加编码容错issue#I3UZ28@Gitee
### 🐞Bug修复
* 【core 】 修复DateUtil.rangeToList中step小于等于0时无限循环问题issue#3783@Github

View File

@ -34,10 +34,7 @@ import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.function.Consumer;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import java.util.zip.*;
/**
* 压缩工具类
@ -65,6 +62,17 @@ public class ZipUtil {
try {
return new ZipFile(file, ObjectUtil.defaultIfNull(charset, CharsetUtil.CHARSET_UTF_8));
} catch (IOException e) {
// issue#I3UZ28 可能编码错误提示
if(e instanceof ZipException){
if(e.getMessage().contains("invalid CEN header")){
try {
// 尝试使用不同编码
return new ZipFile(file, CharsetUtil.CHARSET_UTF_8.equals(charset) ? CharsetUtil.CHARSET_GBK : CharsetUtil.CHARSET_UTF_8);
} catch (final IOException ex) {
throw new IORuntimeException(ex);
}
}
}
throw new IORuntimeException(e);
}
}