Class InputStreamByteSupplier

java.lang.Object
cool.scx.io.supplier.InputStreamByteSupplier
All Implemented Interfaces:
ByteSupplier, AutoCloseable

public final class InputStreamByteSupplier extends Object implements ByteSupplier
InputStreamByteSupplier 1, 当大部分时候读取的数据长度等于 bufferLength 的时候, 性能会高一点 因为只会进行数组创建这一步 2, 当大部分时候读取的数据长度小于 bufferLength 的时候, 性能会差一点 因为每次都会创建一个 bufferLength 大小的数组 如果启用压缩则会产生第二次复制 增加时间 如果未启用压缩则会造成内存上的一些浪费 这时建议使用 BufferedInputStreamByteSupplier
Version:
0.0.1
Author:
scx567888
  • Constructor Details

    • InputStreamByteSupplier

      public InputStreamByteSupplier(InputStream inputStream)
    • InputStreamByteSupplier

      public InputStreamByteSupplier(InputStream inputStream, boolean compress)
    • InputStreamByteSupplier

      public InputStreamByteSupplier(InputStream inputStream, int bufferLength)
    • InputStreamByteSupplier

      public InputStreamByteSupplier(InputStream inputStream, int bufferLength, boolean compress)
  • Method Details

    • get

      public ByteChunk get() throws IOException
      Description copied from interface: ByteSupplier

      获取下一个数据块

      • 必须是推进式的阻塞拉取
      • 如果当前已经读取到有效数据 -> 返回 ByteChunk(len > 0)
      • 如果暂时无法输出数据, 但 I/O 状态确实推进了 -> 返回 EMPTY_BYTE_CHUNK
      • 如果 EOF 且不会再产生数据 -> 返回 null
      • 不允许无状态的空循环: 供应者不得无意义地连续返回 EMPTY_BYTE_CHUNK
      • 连续多次调用 get() 必须使底层数据源或解码状态单调推进
      Specified by:
      get in interface ByteSupplier
      Returns:
      ByteChunk.
      Throws:
      IOException
    • close

      public void close() throws IOException
      Description copied from interface: ByteSupplier
      如果持有底层资源, 在此方法释放资源
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface ByteSupplier
      Throws:
      IOException
    • inputStream

      public InputStream inputStream()