java.lang.Object
org.miaixz.bus.core.io.sink.RealSink
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Channel,WritableByteChannel,BufferSink,Sink
实现缓冲接收器,管理字节流的写入操作,支持多种数据格式的写入并适配底层接收器。
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuffer()获取内部缓冲区。voidclose()关闭接收器,释放资源。emit()将所有缓冲数据写入底层接收器。将完整的缓冲段写入底层接收器。voidflush()刷新缓冲区,将所有数据写入底层接收器。booleanisOpen()检查接收器是否打开。获取适配此接收器的输出流。timeout()获取底层接收器的超时配置。toString()返回对象的字符串表示。write(byte[] source) 写入字节数组。write(byte[] source, int offset, int byteCount) 写入字节数组的指定部分。intwrite(ByteBuffer source) 从 ByteBuffer 写入数据。void从源缓冲区写入指定字节数。write(ByteString byteString) 写入字节字符串。从源读取指定字节数并写入接收器。long从源读取所有数据并写入接收器。writeByte(int b) 写入单个字节。writeDecimalLong(long v) 以十进制形式写入长整型。writeHexadecimalUnsignedLong(long v) 以十六进制形式写入无符号长整型。writeInt(int i) 使用大端序写入整型。writeIntLe(int i) 使用小端序写入整型。writeLong(long v) 使用大端序写入长整型。writeLongLe(long v) 使用小端序写入长整型。writeShort(int s) 使用大端序写入短整型。writeShortLe(int s) 使用小端序写入短整型。writeString(String string, int beginIndex, int endIndex, Charset charset) 使用指定字符集编码写入字符串的指定部分。writeString(String string, Charset charset) 使用指定字符集编码写入字符串。使用 UTF-8 编码写入字符串。使用 UTF-8 编码写入字符串的指定部分。writeUtf8CodePoint(int codePoint) 使用 UTF-8 编码写入 Unicode 码点。
-
Field Details
-
buffer
内部缓冲区 -
sink
底层接收器
-
-
Constructor Details
-
RealSink
构造方法,初始化接收器。- Parameters:
sink- 底层接收器- Throws:
NullPointerException- 如果 sink 为 null
-
-
Method Details
-
buffer
获取内部缓冲区。- Specified by:
bufferin interfaceBufferSink- Returns:
- 内部缓冲区
-
write
从源缓冲区写入指定字节数。- Specified by:
writein interfaceSink- Parameters:
source- 数据源缓冲区byteCount- 要写入的字节数- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
write
写入字节字符串。- Specified by:
writein interfaceBufferSink- Parameters:
byteString- 字节字符串- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeUtf8
使用 UTF-8 编码写入字符串。- Specified by:
writeUtf8in interfaceBufferSink- Parameters:
string- 输入字符串- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeUtf8
使用 UTF-8 编码写入字符串的指定部分。- Specified by:
writeUtf8in interfaceBufferSink- Parameters:
string- 输入字符串beginIndex- 起始索引endIndex- 结束索引- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeUtf8CodePoint
使用 UTF-8 编码写入 Unicode 码点。- Specified by:
writeUtf8CodePointin interfaceBufferSink- Parameters:
codePoint- Unicode 码点- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeString
使用指定字符集编码写入字符串。- Specified by:
writeStringin interfaceBufferSink- Parameters:
string- 输入字符串charset- 字符集- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeString
public BufferSink writeString(String string, int beginIndex, int endIndex, Charset charset) throws IOException 使用指定字符集编码写入字符串的指定部分。- Specified by:
writeStringin interfaceBufferSink- Parameters:
string- 输入字符串beginIndex- 起始索引endIndex- 结束索引charset- 字符集- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
write
写入字节数组。- Specified by:
writein interfaceBufferSink- Parameters:
source- 字节数组- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
write
写入字节数组的指定部分。- Specified by:
writein interfaceBufferSink- Parameters:
source- 字节数组offset- 起始偏移量byteCount- 写入字节数- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
write
从 ByteBuffer 写入数据。- Specified by:
writein interfaceWritableByteChannel- Parameters:
source- 数据源 ByteBuffer- Returns:
- 写入的字节数
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeAll
从源读取所有数据并写入接收器。- Specified by:
writeAllin interfaceBufferSink- Parameters:
source- 数据源- Returns:
- 读取的总字节数
- Throws:
IOException- 如果读取或写入失败IllegalArgumentException- 如果 source 为 null
-
write
从源读取指定字节数并写入接收器。- Specified by:
writein interfaceBufferSink- Parameters:
source- 数据源byteCount- 要读取的字节数- Returns:
- 当前接收器
- Throws:
IOException- 如果读取或写入失败EOFException- 如果源数据不足
-
writeByte
写入单个字节。- Specified by:
writeBytein interfaceBufferSink- Parameters:
b- 字节值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeShort
使用大端序写入短整型。- Specified by:
writeShortin interfaceBufferSink- Parameters:
s- 短整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeShortLe
使用小端序写入短整型。- Specified by:
writeShortLein interfaceBufferSink- Parameters:
s- 短整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeInt
使用大端序写入整型。- Specified by:
writeIntin interfaceBufferSink- Parameters:
i- 整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeIntLe
使用小端序写入整型。- Specified by:
writeIntLein interfaceBufferSink- Parameters:
i- 整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeLong
使用大端序写入长整型。- Specified by:
writeLongin interfaceBufferSink- Parameters:
v- 长整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeLongLe
使用小端序写入长整型。- Specified by:
writeLongLein interfaceBufferSink- Parameters:
v- 长整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeDecimalLong
以十进制形式写入长整型。- Specified by:
writeDecimalLongin interfaceBufferSink- Parameters:
v- 长整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
writeHexadecimalUnsignedLong
以十六进制形式写入无符号长整型。- Specified by:
writeHexadecimalUnsignedLongin interfaceBufferSink- Parameters:
v- 长整型值- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
emitCompleteSegments
将完整的缓冲段写入底层接收器。- Specified by:
emitCompleteSegmentsin interfaceBufferSink- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
emit
将所有缓冲数据写入底层接收器。- Specified by:
emitin interfaceBufferSink- Returns:
- 当前接收器
- Throws:
IOException- 如果写入失败IllegalStateException- 如果接收器已关闭
-
outputStream
获取适配此接收器的输出流。- Specified by:
outputStreamin interfaceBufferSink- Returns:
- 输出流
-
flush
刷新缓冲区,将所有数据写入底层接收器。- Specified by:
flushin interfaceBufferSink- Specified by:
flushin interfaceFlushable- Specified by:
flushin interfaceSink- Throws:
IOException- 如果刷新失败IllegalStateException- 如果接收器已关闭
-
isOpen
public boolean isOpen()检查接收器是否打开。 -
close
public void close()关闭接收器,释放资源。 -
timeout
获取底层接收器的超时配置。 -
toString
返回对象的字符串表示。
-