Class WriteBuffer

java.lang.Object
java.io.OutputStream
org.aoju.bus.socket.buffers.WriteBuffer
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class WriteBuffer extends OutputStream
包装当前会话分配到的虚拟Buffer,提供流式操作方式
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

  • Method Details

    • write

      public void write(int b)
      按照OutputStream.write(int)规范:要写入的字节是参数 b 的八个低位。 b 的 24 个高位将被忽略。 而使用该接口时容易传入非byte范围内的数据,接口定义与实际使用出现歧义的可能性较大,故建议废弃该方法,选用writeByte(byte)
      Specified by:
      write in class OutputStream
      Parameters:
      b - 输出字节
    • writeShort

      public void writeShort(short v) throws IOException
      输出一个short类型的数据
      Parameters:
      v - short数值
      Throws:
      IOException - IO异常
    • writeByte

      public void writeByte(byte b)
      Parameters:
      b - 待输出数值
      See Also:
    • writeInt

      public void writeInt(int v) throws IOException
      输出int数值,占用4个字节
      Parameters:
      v - int数值
      Throws:
      IOException - IO异常
    • writeLong

      public void writeLong(long v) throws IOException
      输出long数值,占用8个字节
      Parameters:
      v - long数值
      Throws:
      IOException - IO异常
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(ByteBuffer buffer)
    • write

      public void write(VirtualBuffer virtualBuffer)
    • writeAndFlush

      public void writeAndFlush(byte[] b) throws IOException
      写入内容并刷新缓冲区。在MessageProcessor.process(AioSession, Object)执行的write操作可无需调用该方法,业务执行完毕后框架本身会自动触发flush 调用该方法后数据会及时的输出到对端,如果再循环体中通过该方法往某个通道中写入数据将无法获得最佳性能表现
      Parameters:
      b - 待输出数据
      Throws:
      IOException - 如果发生 I/O 错误
    • writeAndFlush

      public void writeAndFlush(byte[] b, int off, int len) throws IOException
      Parameters:
      b - 待输出数据
      off - b的起始位点
      len - 从b中输出的数据长度
      Throws:
      IOException - 如果发生 I/O 错误
      See Also:
    • flush

      public void flush()
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
    • isEmpty

      public boolean isEmpty()
      是否存在待输出的数据
      Returns:
      true:有,false:无
    • pollItem

      public VirtualBuffer pollItem()
    • poll

      public VirtualBuffer poll()
      获取并移除当前缓冲队列中头部的VirtualBuffer
      Returns:
      待输出的VirtualBuffer