mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add HttpResource
This commit is contained in:
@@ -32,6 +32,7 @@ import java.io.PushbackInputStream;
|
||||
import java.io.PushbackReader;
|
||||
import java.io.Reader;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
@@ -622,6 +623,9 @@ public class IoUtil extends NioUtil {
|
||||
if (in == null) {
|
||||
throw new IllegalArgumentException("The InputStream must not be null");
|
||||
}
|
||||
if(null != clazz){
|
||||
in.accept(clazz);
|
||||
}
|
||||
try {
|
||||
//noinspection unchecked
|
||||
return (T) in.readObject();
|
||||
@@ -1331,4 +1335,19 @@ public class IoUtil extends NioUtil {
|
||||
public static LineIter lineIter(InputStream in, Charset charset) {
|
||||
return new LineIter(in, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ByteArrayOutputStream} 转换为String
|
||||
* @param out {@link ByteArrayOutputStream}
|
||||
* @param charset 编码
|
||||
* @return 字符串
|
||||
* @since 5.7.17
|
||||
*/
|
||||
public static String toStr(ByteArrayOutputStream out, Charset charset){
|
||||
try {
|
||||
return out.toString(charset.name());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ 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 cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -59,7 +60,7 @@ public class CharSequenceResource implements Resource, Serializable {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name.toString();
|
||||
return StrUtil.str(this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user