mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix bug
This commit is contained in:
parent
8705f1b67c
commit
03e3df7729
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.7.18 (2021-12-22)
|
||||
# 5.7.18 (2021-12-23)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 新增CollStreamUtil.groupKeyValue(pr#479@Gitee)
|
||||
@ -24,6 +24,7 @@
|
||||
* 【core 】 修复StrUtil.startWith都为null返回错误问题(issue#I4MV7Q@Gitee)
|
||||
* 【core 】 修复PasswdStrength检测问题(issue#I4N48X@Gitee)
|
||||
* 【core 】 修复UserAgentUtil解析EdgA无法识别问题(issue#I4MCBP@Gitee)
|
||||
* 【extra 】 修复Archiver路径前带/问题(issue#I4NS0F@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.7.17 (2021-12-09)
|
||||
|
@ -40,6 +40,10 @@ public class CharSequenceUtilTest {
|
||||
|
||||
result = CharSequenceUtil.addSuffixIfNot(str, " is Good");
|
||||
Assert.assertEquals( str + " is Good", result);
|
||||
|
||||
// https://gitee.com/dromara/hutool/issues/I4NS0F
|
||||
result = CharSequenceUtil.addSuffixIfNot("", "/");
|
||||
Assert.assertEquals( "/", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Filter;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile;
|
||||
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
|
||||
@ -125,14 +126,23 @@ public class SevenZArchiver implements Archiver {
|
||||
}
|
||||
final SevenZOutputFile out = this.sevenZOutputFile;
|
||||
|
||||
final String entryName = StrUtil.addSuffixIfNot(StrUtil.nullToEmpty(path), StrUtil.SLASH) + file.getName();
|
||||
final String entryName;
|
||||
if(StrUtil.isNotEmpty(path)){
|
||||
// 非空拼接路径,格式为:path/name
|
||||
entryName = StrUtil.addSuffixIfNot(path, StrUtil.SLASH) + file.getName();
|
||||
} else{
|
||||
// 路径空直接使用文件名或目录名
|
||||
entryName = file.getName();
|
||||
}
|
||||
out.putArchiveEntry(out.createArchiveEntry(file, entryName));
|
||||
|
||||
if (file.isDirectory()) {
|
||||
// 目录遍历写入
|
||||
final File[] files = file.listFiles();
|
||||
for (File childFile : files) {
|
||||
addInternal(childFile, entryName, filter);
|
||||
if(ArrayUtil.isNotEmpty(files)){
|
||||
for (File childFile : files) {
|
||||
addInternal(childFile, entryName, filter);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (file.isFile()) {
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Filter;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.compress.CompressException;
|
||||
import org.apache.commons.compress.archivers.ArchiveException;
|
||||
@ -140,7 +141,7 @@ public class StreamArchiver implements Archiver {
|
||||
* 将文件或目录加入归档包,目录采取递归读取方式按照层级加入
|
||||
*
|
||||
* @param file 文件或目录
|
||||
* @param path 文件或目录的初始路径,null表示位于根路径
|
||||
* @param path 文件或目录的初始路径,{@code null}表示位于根路径
|
||||
* @param filter 文件过滤器,指定哪些文件或目录可以加入,当{@link Filter#accept(Object)}为true时加入。
|
||||
*/
|
||||
private void addInternal(File file, String path, Filter<File> filter) throws IOException {
|
||||
@ -149,14 +150,23 @@ public class StreamArchiver implements Archiver {
|
||||
}
|
||||
final ArchiveOutputStream out = this.out;
|
||||
|
||||
final String entryName = StrUtil.addSuffixIfNot(StrUtil.nullToEmpty(path), StrUtil.SLASH) + file.getName();
|
||||
final String entryName;
|
||||
if(StrUtil.isNotEmpty(path)){
|
||||
// 非空拼接路径,格式为:path/name
|
||||
entryName = StrUtil.addSuffixIfNot(path, StrUtil.SLASH) + file.getName();
|
||||
} else{
|
||||
// 路径空直接使用文件名或目录名
|
||||
entryName = file.getName();
|
||||
}
|
||||
out.putArchiveEntry(out.createArchiveEntry(file, entryName));
|
||||
|
||||
if (file.isDirectory()) {
|
||||
// 目录遍历写入
|
||||
final File[] files = file.listFiles();
|
||||
for (File childFile : files) {
|
||||
addInternal(childFile, entryName, filter);
|
||||
if(ArrayUtil.isNotEmpty(files)){
|
||||
for (File childFile : files) {
|
||||
addInternal(childFile, entryName, filter);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (file.isFile()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user