Package org.miaixz.bus.socket.buffers
Class WriteBuffer
java.lang.Object
java.io.OutputStream
org.miaixz.bus.socket.buffers.WriteBuffer
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
包装当前会话分配到的虚拟Buffer,提供流式操作方式
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
ConstructorsConstructorDescriptionWriteBuffer(BufferPage bufferPage, Consumer<WriteBuffer> consumer, int chunkSize, int capacity) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()booleanisEmpty()是否存在待输出的数据poll()获取并移除当前缓冲队列中头部的VirtualBufferpollItem()voidwrite(byte[] b, int off, int len) voidwrite(int b) 按照OutputStream.write(int)规范:要写入的字节是参数 b 的八个低位。 b 的 24 个高位将被忽略。 而使用该接口时容易传入非byte范围内的数据,接口定义与实际使用出现歧义的可能性较大,故建议废弃该方法,选用writeByte(byte)。voidwrite(ByteBuffer buffer) voidwrite(VirtualBuffer virtualBuffer) voidwriteAndFlush(byte[] b) 写入内容并刷新缓冲区。在MessageProcessor.process(AioSession, Object)执行的write操作可无需调用该方法,业务执行完毕后框架本身会自动触发flush 调用该方法后数据会及时的输出到对端,如果再循环体中通过该方法往某个通道中写入数据将无法获得最佳性能表现voidwriteAndFlush(byte[] b, int off, int len) voidwriteByte(byte b) voidwriteInt(int v) 输出int数值,占用4个字节voidwriteLong(long v) 输出long数值,占用8个字节voidwriteShort(short v) 输出一个short类型的数据Methods inherited from class java.io.OutputStream
nullOutputStream, write
-
Constructor Details
-
WriteBuffer
public WriteBuffer(BufferPage bufferPage, Consumer<WriteBuffer> consumer, int chunkSize, int capacity)
-
-
Method Details
-
write
public void write(int b) 按照OutputStream.write(int)规范:要写入的字节是参数 b 的八个低位。 b 的 24 个高位将被忽略。 而使用该接口时容易传入非byte范围内的数据,接口定义与实际使用出现歧义的可能性较大,故建议废弃该方法,选用writeByte(byte)。- Specified by:
writein classOutputStream- Parameters:
b- 输出字节
-
writeShort
输出一个short类型的数据- Parameters:
v- short数值- Throws:
IOException- IO异常
-
writeByte
public void writeByte(byte b) - Parameters:
b- 待输出数值- See Also:
-
writeInt
输出int数值,占用4个字节- Parameters:
v- int数值- Throws:
IOException- IO异常
-
writeLong
输出long数值,占用8个字节- Parameters:
v- long数值- Throws:
IOException- IO异常
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
-
write
-
writeAndFlush
写入内容并刷新缓冲区。在MessageProcessor.process(AioSession, Object)执行的write操作可无需调用该方法,业务执行完毕后框架本身会自动触发flush 调用该方法后数据会及时的输出到对端,如果再循环体中通过该方法往某个通道中写入数据将无法获得最佳性能表现- Parameters:
b- 待输出数据- Throws:
IOException- 如果发生 I/O 错误
-
writeAndFlush
- Parameters:
b- 待输出数据off- b的起始位点len- 从b中输出的数据长度- Throws:
IOException- 如果发生 I/O 错误- See Also:
-
flush
public void flush()- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream
-
isEmpty
public boolean isEmpty()是否存在待输出的数据- Returns:
- true:有,false:无
-
pollItem
-
poll
获取并移除当前缓冲队列中头部的VirtualBuffer- Returns:
- 待输出的VirtualBuffer
-