mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
99d1835e38
commit
2e349104a3
@ -2,6 +2,7 @@ package cn.hutool.core.map;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.exceptions.UtilException;
|
||||||
import cn.hutool.core.lang.Editor;
|
import cn.hutool.core.lang.Editor;
|
||||||
import cn.hutool.core.lang.Filter;
|
import cn.hutool.core.lang.Filter;
|
||||||
import cn.hutool.core.lang.Pair;
|
import cn.hutool.core.lang.Pair;
|
||||||
@ -242,10 +243,15 @@ public class MapUtil {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <K, V> Map<K, V> createMap(Class<?> mapType) {
|
public static <K, V> Map<K, V> createMap(Class<?> mapType) {
|
||||||
if (mapType.isAssignableFrom(AbstractMap.class)) {
|
if (null == mapType || mapType.isAssignableFrom(AbstractMap.class)) {
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
} else {
|
} else {
|
||||||
return (Map<K, V>) ReflectUtil.newInstance(mapType);
|
try{
|
||||||
|
return (Map<K, V>) ReflectUtil.newInstance(mapType);
|
||||||
|
}catch (UtilException e){
|
||||||
|
// 不支持的map类型,返回默认的HashMap
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -836,6 +836,9 @@ public class ReflectUtil {
|
|||||||
public static <T> T newInstance(Class<T> clazz, Object... params) throws UtilException {
|
public static <T> T newInstance(Class<T> clazz, Object... params) throws UtilException {
|
||||||
if (ArrayUtil.isEmpty(params)) {
|
if (ArrayUtil.isEmpty(params)) {
|
||||||
final Constructor<T> constructor = getConstructor(clazz);
|
final Constructor<T> constructor = getConstructor(clazz);
|
||||||
|
if(null == constructor){
|
||||||
|
throw new UtilException("No constructor for [{}]", clazz);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return constructor.newInstance();
|
return constructor.newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -156,6 +156,7 @@ public class ZipUtilTest {
|
|||||||
//https://github.com/dromara/hutool/issues/944
|
//https://github.com/dromara/hutool/issues/944
|
||||||
String dir = "d:/test";
|
String dir = "d:/test";
|
||||||
String zip = "d:/test.zip";
|
String zip = "d:/test.zip";
|
||||||
|
//noinspection IOStreamConstructor
|
||||||
try (OutputStream out = new FileOutputStream(zip)){
|
try (OutputStream out = new FileOutputStream(zip)){
|
||||||
//实际应用中, out 为 HttpServletResponse.getOutputStream
|
//实际应用中, out 为 HttpServletResponse.getOutputStream
|
||||||
ZipUtil.zip(out, Charset.defaultCharset(), false, null, new File(dir));
|
ZipUtil.zip(out, Charset.defaultCharset(), false, null, new File(dir));
|
||||||
@ -200,9 +201,10 @@ public class ZipUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SizeUnzip() throws IOException {
|
@Ignore
|
||||||
String zipPath = "F:\\BaiduNetdiskDownload\\demo.zip";
|
public void sizeUnzipTest() throws IOException {
|
||||||
String outPath = "F:\\BaiduNetdiskDownload\\test";
|
String zipPath = "e:\\hutool\\demo.zip";
|
||||||
|
String outPath = "e:\\hutool\\test";
|
||||||
ZipFile zipFile = new ZipFile(zipPath, Charset.forName("GBK"));
|
ZipFile zipFile = new ZipFile(zipPath, Charset.forName("GBK"));
|
||||||
File file = new File(outPath);
|
File file = new File(outPath);
|
||||||
// 限制解压文件大小为637KB
|
// 限制解压文件大小为637KB
|
||||||
|
2
pom.xml
2
pom.xml
@ -104,7 +104,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.1.1</version>
|
<version>3.4.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user