Class ByteSink
java.lang.Object
cloud.opencode.base.io.source.ByteSink
Abstract Byte Sink - A writable destination for bytes
抽象字节接收器 - 可写的字节目标
An abstraction over different destinations for byte data.
Counterpart to ByteSource.
对不同字节数据目标的抽象。是ByteSource的对应物。
Features | 主要功能:
- Unified byte writing - 统一的字节写入
- Write from InputStream - 从输入流写入
- Write byte arrays - 写入字节数组
- Support for append mode - 支持追加模式
Usage Examples | 使用示例:
// Write to file
ByteSink sink = ByteSink.toPath(Paths.get("output.bin"));
sink.write(data);
// Copy from source to sink
ByteSource source = ByteSource.fromPath(Paths.get("input.bin"));
source.copyTo(sink);
Security | 安全性:
- Thread-safe: No, not safe for concurrent writes - 线程安全: 否,不支持并发写入
- Null-safe: No, data must not be null - 空值安全: 否,数据不可为null
- Since:
- JDK 25, opencode-base-io V1.2.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a view of this sink as a CharSink with UTF-8 charset.asCharSink(Charset charset) Returns a view of this sink as a CharSink with the given charset.static ByteSinknullSink()Creates a ByteSink that discards all written data.abstract OutputStreamOpens a new OutputStream for writing.static ByteSinkCreates a ByteSink for writing to a file path.static ByteSinktoPathAppend(Path path) Creates a ByteSink for appending to a file path.voidwrite(byte[] bytes) Writes all bytes from a byte array.longwriteFrom(InputStream input) Writes all bytes from an InputStream.
-
Constructor Details
-
ByteSink
public ByteSink()
-
-
Method Details
-
openStream
Opens a new OutputStream for writing. 打开新的输出流进行写入。The caller is responsible for closing the stream.
调用者负责关闭流。
- Returns:
- a new OutputStream | 新的输出流
- Throws:
OpenIOOperationException- if the stream cannot be opened | 如果流无法打开
-
asCharSink
-
asCharSink
Returns a view of this sink as a CharSink with UTF-8 charset. 返回使用UTF-8字符集作为CharSink的此接收器视图。- Returns:
- a CharSink view | CharSink视图
-
write
public void write(byte[] bytes) Writes all bytes from a byte array. 从字节数组写入所有字节。- Parameters:
bytes- the bytes to write | 要写入的字节- Throws:
OpenIOOperationException- if writing fails | 如果写入失败
-
writeFrom
Writes all bytes from an InputStream. 从输入流写入所有字节。- Parameters:
input- the input stream | 输入流- Returns:
- the number of bytes written | 写入的字节数
- Throws:
OpenIOOperationException- if writing fails | 如果写入失败
-
toPath
-
toPathAppend
-
nullSink
Creates a ByteSink that discards all written data. 创建丢弃所有写入数据的ByteSink。- Returns:
- a null ByteSink | 空ByteSink
-