Module bus.core

Interface BufferSink

All Superinterfaces:
AutoCloseable, Channel, Closeable, Flushable, Sink, WritableByteChannel
All Known Implementing Classes:
Buffer, RealSink

public interface BufferSink extends Sink, WritableByteChannel
缓冲接收器接口,提供高效的写操作,内部维护缓冲区以减少性能开销。
Since:
Java 17+
Author:
Kimi Liu
  • Method Details

    • buffer

      Buffer buffer()
      获取内部缓冲区。
      Returns:
      内部缓冲区对象
    • write

      BufferSink write(ByteString byteString) throws IOException
      写入字节字符串。
      Parameters:
      byteString - 字节字符串
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • write

      BufferSink write(byte[] source) throws IOException
      写入完整的字节数组。
      Parameters:
      source - 字节数组
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • write

      BufferSink write(byte[] source, int offset, int byteCount) throws IOException
      写入字节数组的指定部分。
      Parameters:
      source - 字节数组
      offset - 起始偏移量
      byteCount - 写入字节数
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeAll

      long writeAll(Source source) throws IOException
      从源读取所有字节并写入接收器。
      Parameters:
      source - 数据源
      Returns:
      读取的字节数,源耗尽时返回 0
      Throws:
      IOException - 如果读取或写入失败
    • write

      BufferSink write(Source source, long byteCount) throws IOException
      从源读取指定字节数并写入接收器。
      Parameters:
      source - 数据源
      byteCount - 要读取的字节数
      Returns:
      当前接收器
      Throws:
      IOException - 如果读取或写入失败
    • writeUtf8

      BufferSink writeUtf8(String string) throws IOException
      使用 UTF-8 编码写入字符串。
      Parameters:
      string - 输入字符串
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeUtf8

      BufferSink writeUtf8(String string, int beginIndex, int endIndex) throws IOException
      使用 UTF-8 编码写入字符串的指定部分。
      Parameters:
      string - 输入字符串
      beginIndex - 起始索引
      endIndex - 结束索引
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeUtf8CodePoint

      BufferSink writeUtf8CodePoint(int codePoint) throws IOException
      使用 UTF-8 编码写入 Unicode 码点。
      Parameters:
      codePoint - Unicode 码点
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeString

      BufferSink writeString(String string, Charset charset) throws IOException
      使用指定字符集编码写入字符串。
      Parameters:
      string - 输入字符串
      charset - 字符集
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeString

      BufferSink writeString(String string, int beginIndex, int endIndex, Charset charset) throws IOException
      使用指定字符集编码写入字符串的指定部分。
      Parameters:
      string - 输入字符串
      beginIndex - 起始索引
      endIndex - 结束索引
      charset - 字符集
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeByte

      BufferSink writeByte(int b) throws IOException
      写入单个字节。
      Parameters:
      b - 字节值
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeShort

      BufferSink writeShort(int s) throws IOException
      使用大端序写入短整型(2 字节)。
      Parameters:
      s - 短整型值
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeShortLe

      BufferSink writeShortLe(int s) throws IOException
      使用小端序写入短整型(2 字节)。
      Parameters:
      s - 短整型值
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeInt

      BufferSink writeInt(int i) throws IOException
      使用大端序写入整型(4 字节)。
      Parameters:
      i - 整型值
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeIntLe

      BufferSink writeIntLe(int i) throws IOException
      使用小端序写入整型(4 字节)。
      Parameters:
      i - 整型值
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeLong

      BufferSink writeLong(long v) throws IOException
      使用大端序写入长整型(8 字节)。
      Parameters:
      v - 长整型值
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeLongLe

      BufferSink writeLongLe(long v) throws IOException
      使用小端序写入长整型(8 字节)。
      Parameters:
      v - 长整型值
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeDecimalLong

      BufferSink writeDecimalLong(long v) throws IOException
      以十进制形式写入长整型。
      Parameters:
      v - 长整型值
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • writeHexadecimalUnsignedLong

      BufferSink writeHexadecimalUnsignedLong(long v) throws IOException
      以十六进制形式写入无符号长整型。
      Parameters:
      v - 长整型值
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • flush

      void flush() throws IOException
      将缓冲数据写入底层接收器,并递归刷新以推送数据到最终目标。
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in interface Sink
      Throws:
      IOException - 如果写入或刷新失败
    • emit

      BufferSink emit() throws IOException
      将缓冲数据写入底层接收器,较弱的刷新操作,确保数据向目标移动。
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • emitCompleteSegments

      BufferSink emitCompleteSegments() throws IOException
      将完整的缓冲段写入底层接收器,限制缓冲区内存占用。
      Returns:
      当前接收器
      Throws:
      IOException - 如果写入失败
    • outputStream

      OutputStream outputStream()
      获取写入此接收器的输出流。
      Returns:
      输出流