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修复
|
### 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.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.TimeZone;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -524,7 +525,15 @@ public class DateUtil {
|
|||||||
if (null == date || StrUtil.isBlank(format)) {
|
if (null == date || StrUtil.isBlank(format)) {
|
||||||
return null;
|
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
|
* @author Looly
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ZipUtil {
|
public class ZipUtil {
|
||||||
|
|
||||||
private static final int DEFAULT_BYTE_ARRAY_LENGTH = 32;
|
private static final int DEFAULT_BYTE_ARRAY_LENGTH = 32;
|
||||||
|
|
||||||
/** 默认编码,使用平台相关编码 */
|
/**
|
||||||
|
* 默认编码,使用平台相关编码
|
||||||
|
*/
|
||||||
private static final Charset DEFAULT_CHARSET = CharsetUtil.defaultCharset();
|
private static final Charset DEFAULT_CHARSET = CharsetUtil.defaultCharset();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -306,6 +307,7 @@ public class ZipUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------- Unzip
|
// ---------------------------------------------------------------------------------------------- Unzip
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解压到文件名相同的目录中,默认编码UTF-8
|
* 解压到文件名相同的目录中,默认编码UTF-8
|
||||||
*
|
*
|
||||||
@@ -433,6 +435,7 @@ public class ZipUtil {
|
|||||||
outItemFile = buildFile(outFile, zipEntry.getName());
|
outItemFile = buildFile(outFile, zipEntry.getName());
|
||||||
if (zipEntry.isDirectory()) {
|
if (zipEntry.isDirectory()) {
|
||||||
// 创建对应目录
|
// 创建对应目录
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
outItemFile.mkdirs();
|
outItemFile.mkdirs();
|
||||||
} else {
|
} else {
|
||||||
// 写出文件
|
// 写出文件
|
||||||
@@ -564,6 +567,7 @@ public class ZipUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- Gzip
|
// ----------------------------------------------------------------------------- Gzip
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gzip压缩处理
|
* Gzip压缩处理
|
||||||
*
|
*
|
||||||
@@ -849,6 +853,7 @@ public class ZipUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------- Private method start
|
// ---------------------------------------------------------------------------------------------- Private method start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得 {@link ZipOutputStream}
|
* 获得 {@link ZipOutputStream}
|
||||||
*
|
*
|
||||||
@@ -1068,8 +1073,16 @@ public class ZipUtil {
|
|||||||
private static File buildFile(File outFile, String fileName) {
|
private static File buildFile(File outFile, String fileName) {
|
||||||
if (false == FileUtil.isWindows() && StrUtil.contains(fileName, CharUtil.SLASH)) {
|
if (false == FileUtil.isWindows() && StrUtil.contains(fileName, CharUtil.SLASH)) {
|
||||||
// 在Linux下多层目录创建存在问题,/会被当成文件名的一部分,此处做处理
|
// 在Linux下多层目录创建存在问题,/会被当成文件名的一部分,此处做处理
|
||||||
|
// 使用/拆分路径(zip中无\),级联创建父目录
|
||||||
final String[] pathParts = StrUtil.splitToArray(fileName, CharUtil.SLASH);
|
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);
|
return FileUtil.file(outFile, fileName);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user