- All Superinterfaces:
AutoCloseable,Channel,Closeable,Flushable,Sink,WritableByteChannel
缓冲接收器接口,提供高效的写操作,内部维护缓冲区以减少性能开销。
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Method Summary
Modifier and TypeMethodDescriptionbuffer()获取内部缓冲区。emit()将缓冲数据写入底层接收器,较弱的刷新操作,确保数据向目标移动。将完整的缓冲段写入底层接收器,限制缓冲区内存占用。voidflush()将缓冲数据写入底层接收器,并递归刷新以推送数据到最终目标。获取写入此接收器的输出流。write(byte[] source) 写入完整的字节数组。write(byte[] source, int offset, int byteCount) 写入字节数组的指定部分。write(ByteString byteString) 写入字节字符串。从源读取指定字节数并写入接收器。long从源读取所有字节并写入接收器。writeByte(int b) 写入单个字节。writeDecimalLong(long v) 以十进制形式写入长整型。writeHexadecimalUnsignedLong(long v) 以十六进制形式写入无符号长整型。writeInt(int i) 使用大端序写入整型(4 字节)。writeIntLe(int i) 使用小端序写入整型(4 字节)。writeLong(long v) 使用大端序写入长整型(8 字节)。writeLongLe(long v) 使用小端序写入长整型(8 字节)。writeShort(int s) 使用大端序写入短整型(2 字节)。writeShortLe(int s) 使用小端序写入短整型(2 字节)。writeString(String string, int beginIndex, int endIndex, Charset charset) 使用指定字符集编码写入字符串的指定部分。writeString(String string, Charset charset) 使用指定字符集编码写入字符串。使用 UTF-8 编码写入字符串。使用 UTF-8 编码写入字符串的指定部分。writeUtf8CodePoint(int codePoint) 使用 UTF-8 编码写入 Unicode 码点。Methods inherited from interface java.nio.channels.WritableByteChannel
write
-
Method Details
-
buffer
Buffer buffer()获取内部缓冲区。- Returns:
- 内部缓冲区对象
-
write
写入字节字符串。- Parameters:
byteString- 字节字符串- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
write
写入完整的字节数组。- Parameters:
source- 字节数组- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
write
写入字节数组的指定部分。- Parameters:
source- 字节数组offset- 起始偏移量byteCount- 写入字节数- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeAll
从源读取所有字节并写入接收器。- Parameters:
source- 数据源- Returns:
- 读取的字节数,源耗尽时返回 0
- Throws:
IOException- 如果读取或写入失败
-
write
从源读取指定字节数并写入接收器。- Parameters:
source- 数据源byteCount- 要读取的字节数- Returns:
- 当前接收器
- Throws:
IOException- 如果读取或写入失败
-
writeUtf8
使用 UTF-8 编码写入字符串。- Parameters:
string- 输入字符串- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeUtf8
使用 UTF-8 编码写入字符串的指定部分。- Parameters:
string- 输入字符串beginIndex- 起始索引endIndex- 结束索引- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeUtf8CodePoint
使用 UTF-8 编码写入 Unicode 码点。- Parameters:
codePoint- Unicode 码点- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeString
使用指定字符集编码写入字符串。- 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
写入单个字节。- Parameters:
b- 字节值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeShort
使用大端序写入短整型(2 字节)。- Parameters:
s- 短整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeShortLe
使用小端序写入短整型(2 字节)。- Parameters:
s- 短整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeInt
使用大端序写入整型(4 字节)。- Parameters:
i- 整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeIntLe
使用小端序写入整型(4 字节)。- Parameters:
i- 整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeLong
使用大端序写入长整型(8 字节)。- Parameters:
v- 长整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeLongLe
使用小端序写入长整型(8 字节)。- Parameters:
v- 长整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeDecimalLong
以十进制形式写入长整型。- Parameters:
v- 长整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
writeHexadecimalUnsignedLong
以十六进制形式写入无符号长整型。- Parameters:
v- 长整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
flush
将缓冲数据写入底层接收器,并递归刷新以推送数据到最终目标。- Specified by:
flushin interfaceFlushable- Specified by:
flushin interfaceSink- Throws:
IOException- 如果写入或刷新失败
-
emit
将缓冲数据写入底层接收器,较弱的刷新操作,确保数据向目标移动。- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
emitCompleteSegments
将完整的缓冲段写入底层接收器,限制缓冲区内存占用。- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败
-
outputStream
OutputStream outputStream()获取写入此接收器的输出流。- Returns:
- 输出流
-