java.lang.Object
java.io.OutputStream
org.miaixz.bus.socket.buffer.WriteBuffer
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
包装当前会话分配到的虚拟Buffer,提供流式操作方式
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
ConstructorsConstructorDescriptionWriteBuffer(BufferPage bufferPage, Consumer<VirtualBuffer> writeConsumer, int chunkSize, int capacity) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidvoidflush()booleanisEmpty()是否存在待输出的数据poll()获取并移除当前缓冲队列中头部的VirtualBuffervoidtransferFrom(ByteBuffer byteBuffer, Consumer<WriteBuffer> consumer) voidwrite(byte[] b, int off, int len) voidwrite(byte[] bytes, int offset, int len, Consumer<WriteBuffer> consumer) 执行异步输出操作 此方法会将指定的字节流异步写入,并在完成时通知提供的消费者。voidwrite(byte[] bytes, Consumer<WriteBuffer> consumer) voidwrite(int b) 按照OutputStream.write(int)规范:要写入的字节是参数 b 的八个低位。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<VirtualBuffer> writeConsumer, 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
public void write(byte[] bytes, int offset, int len, Consumer<WriteBuffer> consumer) throws IOException 执行异步输出操作 此方法会将指定的字节流异步写入,并在完成时通知提供的消费者。- Parameters:
bytes- 待输出的字节流。offset- 字节流中开始输出的偏移量。len- 要输出的字节数。consumer- 完成输出后调用的消费者接口,用于处理写入完成后的缓冲区。- Throws:
IOException- 如果在写入过程中发生I/O错误。WritePendingException- 如果已有写入操作未完成,此时再调用此方法会抛出此异常。
-
write
- Throws:
IOException
-
transferFrom
- Throws:
IOException
-
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:无
-
finishWrite
public void finishWrite() -
poll
获取并移除当前缓冲队列中头部的VirtualBuffer- Returns:
- 待输出的VirtualBuffer
-