This commit is contained in:
Looly
2020-05-14 01:56:03 +08:00
parent 3da83e0227
commit d0fe78ae66
14 changed files with 337 additions and 156 deletions

View File

@@ -267,7 +267,7 @@ public class BeanCopier<T> implements Copier<T>, Serializable {
if (null == value && copyOptions.ignoreNullValue) {
continue;// 当允许跳过空时,跳过
}
if (bean.equals(value)) {
if (bean == value) {
continue;// 值不能为bean本身防止循环引用
}

View File

@@ -65,7 +65,9 @@ public class BeanConverter<T> extends AbstractConverter<T> {
@Override
protected T convertInternal(Object value) {
if(value instanceof Map || value instanceof ValueProvider || BeanUtil.isBean(value.getClass())) {
if(value instanceof Map ||
value instanceof ValueProvider ||
BeanUtil.isBean(value.getClass())) {
if(value instanceof Map && this.beanClass.isInterface()) {
// 将Map动态代理为Bean
return MapProxy.create((Map<?, ?>)value).toProxyBean(this.beanClass);

View File

@@ -1001,9 +1001,9 @@ public class IoUtil {
for (Object content : contents) {
if (content != null) {
osw.write(Convert.toStr(content, StrUtil.EMPTY));
osw.flush();
}
}
osw.flush();
} catch (IOException e) {
throw new IORuntimeException(e);
} finally {

View File

@@ -1,11 +1,13 @@
package cn.hutool.core.io.resource;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.CharsetUtil;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.charset.Charset;
@@ -36,6 +38,20 @@ public interface Resource {
* @return {@link InputStream}
*/
InputStream getStream();
/**
* 将资源内容写出到流,不关闭输出流,但是关闭资源流
* @param out 输出流
* @throws IORuntimeException IO异常
* @since 5.3.5
*/
default void writeTo(OutputStream out) throws IORuntimeException{
try (InputStream in = getStream()) {
IoUtil.copy(in, out);
} catch (IOException e) {
throw new IORuntimeException(e);
}
}
/**
* 获得Reader

View File

@@ -397,18 +397,8 @@ public class ObjectUtil {
if (false == (obj instanceof Serializable)) {
return null;
}
FastByteArrayOutputStream byteOut = new FastByteArrayOutputStream();
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(byteOut);
oos.writeObject(obj);
oos.flush();
} catch (Exception e) {
throw new UtilException(e);
} finally {
IoUtil.close(oos);
}
final FastByteArrayOutputStream byteOut = new FastByteArrayOutputStream();
IoUtil.writeObjects(byteOut, false, (Serializable) obj);
return byteOut.toByteArray();
}
@@ -416,20 +406,16 @@ public class ObjectUtil {
* 反序列化<br>
* 对象必须实现Serializable接口
*
* <p>
* 注意!!! 此方法不会检查反序列化安全,可能存在反序列化漏洞风险!!!
* </p>
*
* @param <T> 对象类型
* @param bytes 反序列化的字节码
* @return 反序列化后的对象
*/
@SuppressWarnings("unchecked")
public static <T> T deserialize(byte[] bytes) {
ObjectInputStream ois;
try {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ois = new ObjectInputStream(bais);
return (T) ois.readObject();
} catch (Exception e) {
throw new UtilException(e);
}
return IoUtil.readObj(new ByteArrayInputStream(bytes));
}
/**