类 DataReader

java.lang.Object
com.ajaxjs.util.io.DataReader

public class DataReader extends Object
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

      public DataReader(InputStream in, Charset encode)
      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

      public void readStreamAsBytes(int bufferSize, BiConsumer<Integer,byte[]> fn)
      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

      public void readAsLineString(Consumer<String> fn)
      Read the text data from the input stream as line by line.
      参数:
      fn - provided function to consume each line of data
    • readAsString

      public String 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.