public class StreamReader extends Object
InputStream
读取器Constructor and Description |
---|
StreamReader(InputStream in,
boolean closeAfterRead)
构造
|
Modifier and Type | Method and Description |
---|---|
static StreamReader |
of(InputStream in,
boolean closeAfterRead)
创建读取器
|
FastByteArrayOutputStream |
read()
从流中读取内容,读到输出流中,读取完毕后可选是否关闭流
|
FastByteArrayOutputStream |
read(int limit)
从流中读取内容,读到输出流中,读取完毕后可选是否关闭流
|
byte[] |
readBytes()
从流中读取bytes
|
byte[] |
readBytes(int length)
读取指定长度的byte数组
|
<T> T |
readObj(Class<?>... acceptClasses)
从流中读取对象,即对象的反序列化
注意!!!
|
FastByteArrayOutputStream |
readTo(Predicate<Integer> predicate)
从流中读取内容,直到遇到给定token满足
Predicate.test(Object) |
public StreamReader(InputStream in, boolean closeAfterRead)
in
- InputStream
closeAfterRead
- 读取结束后是否关闭输入流public static StreamReader of(InputStream in, boolean closeAfterRead)
in
- InputStream
closeAfterRead
- 读取结束后是否关闭输入流public byte[] readBytes() throws IORuntimeException
IORuntimeException
- IO异常public byte[] readBytes(int length) throws IORuntimeException
length
- 长度,小于0表示读取全部IORuntimeException
- IO异常public FastByteArrayOutputStream read() throws IORuntimeException
IORuntimeException
- IO异常public FastByteArrayOutputStream read(int limit) throws IORuntimeException
limit
- 限制最大拷贝长度,-1表示无限制IORuntimeException
- IO异常public FastByteArrayOutputStream readTo(Predicate<Integer> predicate) throws IORuntimeException
Predicate.test(Object)
predicate
- 读取结束条件, Predicate.test(Object)
返回true表示结束IORuntimeException
- IO异常public <T> T readObj(Class<?>... acceptClasses) throws IORuntimeException, HutoolException
注意!!! 此方法不会检查反序列化安全,可能存在反序列化漏洞风险!!!
此方法使用了ValidateObjectInputStream
中的黑白名单方式过滤类,用于避免反序列化漏洞
通过构造ValidateObjectInputStream
,调用ValidateObjectInputStream.accept(Class[])
或者ValidateObjectInputStream.refuse(Class[])
方法添加可以被序列化的类或者禁止序列化的类。
T
- 读取对象的类型acceptClasses
- 读取对象类型IORuntimeException
- IO异常HutoolException
- ClassNotFoundException包装Copyright © 2025. All rights reserved.