增加GlobalPoiConfig

This commit is contained in:
Looly 2024-07-30 10:27:38 +08:00
parent 52dad763a0
commit 12aa680335
2 changed files with 60 additions and 2 deletions

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2024. looly(loolly@aliyun.com)
* Hutool is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* https://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package org.dromara.hutool.poi;
import org.apache.poi.openxml4j.util.ZipSecureFile;
/**
* POI的全局设置
*
* @author Looly
* @see ZipSecureFile
* @since 5.8.30
*/
public class GlobalPoiConfig {
/**
* 设置解压时的最小压缩比例<br>
* 为了避免`Zip Bomb`POI中设置了最小压缩比例这个比例为
* <pre>
* 压缩后的大小/解压后的大小
* </pre>
* <p>
* POI的默认值是0.01即最小压缩到1%如果文档中的文件压缩比例小于这个值就会报错<br>
* 如果文件中确实存在高压缩比的文件可以通过这个全局方法自定义比例从而避免错误
*
* @param ratio 解压后的文件大小与原始文件大小的最小比率小于等于0表示不检查
*/
public static void setMinInflateRatio(final double ratio) {
ZipSecureFile.setMinInflateRatio(ratio);
}
/**
* 设置单个Zip文件中最大文件大小默认为4GB即32位zip格式的最大值
*
* @param maxEntrySize 单个Zip文件中最大文件大小必须大于0
*/
public static void setMaxEntrySize(final long maxEntrySize) {
ZipSecureFile.setMaxEntrySize(maxEntrySize);
}
/**
* 设置解压前文本的最大字符数超过抛出异常
*
* @param maxTextSize 文本的最大字符数
* @throws IllegalArgumentException for negative maxTextSize
*/
public static void setMaxTextSize(final long maxTextSize) {
ZipSecureFile.setMaxTextSize(maxTextSize);
}
}

View File

@ -22,8 +22,6 @@ import java.io.File;
*/
public class WordUtil {
/**
* 创建Word 07格式的生成器
*