Interface Source

All Superinterfaces:
AutoCloseable, Closeable
All Known Subinterfaces:
BufferSource
All Known Implementing Classes:
AssignSource, Buffer, GzipSource, InflaterSource, PeekSource, RealSource

public interface Source extends Closeable
提供一个字节流 使用此接口从任何地方读取数据 它的位置:来自网络、存储或内存中的缓冲区 来源可能 分层以转换提供的数据,例如解压、解密或移除协议框架
Since:
Java 17+
Author:
Kimi Liu
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    关闭此源并释放此源持有的资源.
    long
    read(Buffer sink, long byteCount)
    从中删除至少1个字节,最多为byteCount字节, 并将它们 附加到sink。返回读取的字节数,如果该源已耗尽,则返回-1
    返回此源的超时时间.
  • Method Details

    • read

      long read(Buffer sink, long byteCount) throws IOException
      从中删除至少1个字节,最多为byteCount字节, 并将它们 附加到sink。返回读取的字节数,如果该源已耗尽,则返回-1
      Parameters:
      sink - 缓冲
      byteCount - 长度大小
      Returns:
      the long
      Throws:
      IOException - IOException IOException.
    • timeout

      Timeout timeout()
      返回此源的超时时间.
      Returns:
      超时时间
    • close

      void close() throws IOException
      关闭此源并释放此源持有的资源. 读取闭源是一个错误。多次关闭源是安全的.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - IOException IOException.