mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
ZipUtil.unzip增加编码容错(issue#I3UZ28@Gitee)
This commit is contained in:
parent
0ba6c8ecda
commit
4a860c77ff
@ -2,10 +2,11 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.34(2024-11-12)
|
# 5.8.34(2024-11-13)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【http 】 增加Windows微信浏览器识别(issue#IB3SJF@Gitee)
|
* 【http 】 增加Windows微信浏览器识别(issue#IB3SJF@Gitee)
|
||||||
|
* 【core 】 ZipUtil.unzip增加编码容错(issue#I3UZ28@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复DateUtil.rangeToList中step小于等于0时无限循环问题(issue#3783@Github)
|
* 【core 】 修复DateUtil.rangeToList中step小于等于0时无限循环问题(issue#3783@Github)
|
||||||
|
@ -34,10 +34,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.*;
|
||||||
import java.util.zip.ZipFile;
|
|
||||||
import java.util.zip.ZipInputStream;
|
|
||||||
import java.util.zip.ZipOutputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 压缩工具类
|
* 压缩工具类
|
||||||
@ -65,6 +62,17 @@ public class ZipUtil {
|
|||||||
try {
|
try {
|
||||||
return new ZipFile(file, ObjectUtil.defaultIfNull(charset, CharsetUtil.CHARSET_UTF_8));
|
return new ZipFile(file, ObjectUtil.defaultIfNull(charset, CharsetUtil.CHARSET_UTF_8));
|
||||||
} catch (IOException e) {
|
} 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);
|
throw new IORuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user