Package org.miaixz.bus.core.io.stream
Class StreamReader
java.lang.Object
org.miaixz.bus.core.io.stream.StreamReader
InputStream读取器- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StreamReaderof(InputStream in, boolean closeAfterRead) 创建读取器read()从流中读取内容,读到输出流中,读取完毕后可选是否关闭流read(int limit) 从流中读取内容,读到输出流中,读取完毕后可选是否关闭流byte[]从流中读取bytesbyte[]readBytes(int length) 读取指定长度的byte数组<T> TreadObject(Class<?>... acceptClasses) 从流中读取对象,即对象的反序列化
-
Constructor Details
-
StreamReader
构造- Parameters:
in-InputStreamcloseAfterRead- 读取结束后是否关闭输入流
-
-
Method Details
-
of
创建读取器- Parameters:
in-InputStreamcloseAfterRead- 读取结束后是否关闭输入流- Returns:
- StreamReader
-
readBytes
从流中读取bytes- Returns:
- bytes
- Throws:
InternalException- IO异常
-
readBytes
读取指定长度的byte数组- Parameters:
length- 长度,小于0表示读取全部- Returns:
- bytes
- Throws:
InternalException- IO异常
-
read
从流中读取内容,读到输出流中,读取完毕后可选是否关闭流- Returns:
- 输出流
- Throws:
InternalException- IO异常
-
read
从流中读取内容,读到输出流中,读取完毕后可选是否关闭流- Parameters:
limit- 限制最大拷贝长度,-1表示无限制- Returns:
- 输出流
- Throws:
InternalException- IO异常
-
readObject
从流中读取对象,即对象的反序列化注意!!! 此方法不会检查反序列化安全,可能存在反序列化漏洞风险!!!
此方法使用了
ValidateObjectInputStream中的黑白名单方式过滤类,用于避免反序列化漏洞 通过构造ValidateObjectInputStream,调用ValidateObjectInputStream.accept(Class[])或者ValidateObjectInputStream.refuse(Class[])方法添加可以被序列化的类或者禁止序列化的类。- Type Parameters:
T- 读取对象的类型- Parameters:
acceptClasses- 读取对象类型- Returns:
- 输出流
- Throws:
InternalException- IO异常InternalException- ClassNotFoundException包装
-