mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix Date and Zip bugs
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
### 新特性
|
||||
|
||||
### Bug修复
|
||||
* 【core】 修复DateUtil.format使用DateTime时区失效问题(issue#I150I7@Gitee)
|
||||
* 【core】 修复ZipUtil解压目录遗留问题(issue#I14NO3@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@@ -30,6 +30,7 @@ import java.util.GregorianCalendar;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -524,7 +525,15 @@ public class DateUtil {
|
||||
if (null == date || StrUtil.isBlank(format)) {
|
||||
return null;
|
||||
}
|
||||
return format(date, FastDateFormat.getInstance(format));
|
||||
|
||||
final SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||||
if(date instanceof DateTime){
|
||||
final TimeZone timeZone = ((DateTime) date).getTimeZone();
|
||||
if(null != timeZone) {
|
||||
sdf.setTimeZone(timeZone);
|
||||
}
|
||||
}
|
||||
return format(date, sdf);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -34,13 +34,14 @@ import cn.hutool.core.io.IoUtil;
|
||||
* 压缩工具类
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public class ZipUtil {
|
||||
|
||||
private static final int DEFAULT_BYTE_ARRAY_LENGTH = 32;
|
||||
|
||||
/** 默认编码,使用平台相关编码 */
|
||||
/**
|
||||
* 默认编码,使用平台相关编码
|
||||
*/
|
||||
private static final Charset DEFAULT_CHARSET = CharsetUtil.defaultCharset();
|
||||
|
||||
/**
|
||||
@@ -255,7 +256,7 @@ public class ZipUtil {
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public static File zip(File zipFile, String path, InputStream in, Charset charset) throws UtilException {
|
||||
return zip(zipFile, new String[] { path }, new InputStream[] { in }, charset);
|
||||
return zip(zipFile, new String[]{path}, new InputStream[]{in}, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -306,6 +307,7 @@ public class ZipUtil {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- Unzip
|
||||
|
||||
/**
|
||||
* 解压到文件名相同的目录中,默认编码UTF-8
|
||||
*
|
||||
@@ -433,6 +435,7 @@ public class ZipUtil {
|
||||
outItemFile = buildFile(outFile, zipEntry.getName());
|
||||
if (zipEntry.isDirectory()) {
|
||||
// 创建对应目录
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
outItemFile.mkdirs();
|
||||
} else {
|
||||
// 写出文件
|
||||
@@ -564,6 +567,7 @@ public class ZipUtil {
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- Gzip
|
||||
|
||||
/**
|
||||
* Gzip压缩处理
|
||||
*
|
||||
@@ -849,6 +853,7 @@ public class ZipUtil {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- Private method start
|
||||
|
||||
/**
|
||||
* 获得 {@link ZipOutputStream}
|
||||
*
|
||||
@@ -1065,11 +1070,19 @@ public class ZipUtil {
|
||||
* @return 文件或目录
|
||||
* @since 5.0.5
|
||||
*/
|
||||
private static File buildFile(File outFile, String fileName){
|
||||
if(false == FileUtil.isWindows() && StrUtil.contains(fileName, CharUtil.SLASH)) {
|
||||
private static File buildFile(File outFile, String fileName) {
|
||||
if (false == FileUtil.isWindows() && StrUtil.contains(fileName, CharUtil.SLASH)) {
|
||||
// 在Linux下多层目录创建存在问题,/会被当成文件名的一部分,此处做处理
|
||||
// 使用/拆分路径(zip中无\),级联创建父目录
|
||||
final String[] pathParts = StrUtil.splitToArray(fileName, CharUtil.SLASH);
|
||||
return FileUtil.file(pathParts);
|
||||
for (int i = 0; i < pathParts.length - 1; i++) {
|
||||
//由于路径拆分,slip不检查,在最后一步检查
|
||||
outFile = new File(outFile, pathParts[i]);
|
||||
}
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
outFile.mkdirs();
|
||||
// 最后一个部分作为文件名
|
||||
fileName = pathParts[pathParts.length -1];
|
||||
}
|
||||
return FileUtil.file(outFile, fileName);
|
||||
}
|
||||
|
Reference in New Issue
Block a user