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