类 DataReader
java.lang.Object
com.ajaxjs.util.io.DataReader
The reader class for reading data from an input stream.
InputStream is used for reading raw byte data from a source like a file, network socket, or memory buffer.
If its text is not binary data, Reader can be used.
If it does not meet the need, you can refer to the Spring StreamUtils/ResourceUtils/FileCopyUtils/FileSystemUtils.
-
构造器概要
构造器构造器说明DataReader(InputStream in, Charset encode) Create a DataReader instance with the specified input stream and character encoding. -
方法概要
修饰符和类型方法说明byte[]Read the data from the input stream as bytes.voidRead the text data from the input stream as line by line.Read the data from the input stream as a string.voidreadStreamAsBytes(int bufferSize, BiConsumer<Integer, byte[]> fn) Read the binary data from the input stream as bytes.
-
构造器详细资料
-
DataReader
Create a DataReader instance with the specified input stream and character encoding.- 参数:
in- The input stream to read data from.encode- The character encoding to use when reading the input stream.
-
-
方法详细资料
-
readStreamAsBytes
Read the binary data from the input stream as bytes. It will close the input stream when the reading process is complete.- 参数:
bufferSize- The template buffer size.fn- What do you want to do with the data?
-
readAsLineString
Read the text data from the input stream as line by line.- 参数:
fn- provided function to consume each line of data
-
readAsString
Read the data from the input stream as a string.- 返回:
- String
-
readAsBytes
public byte[] readAsBytes()Read the data from the input stream as bytes. This equivalent to using the DataWriter class to write the data to a ByteArrayOutputStream, that means the data is stored in memory.- 返回:
- The bytes in RAM.
-