@GwtIncompatible public abstract class ByteSink extends java.lang.Object
OutputStream
, a
ByteSink
is not an open, stateful stream that can be written to and closed. Instead, it
is an immutable supplier of OutputStream
instances.
ByteSink
provides two kinds of methods:
Modifier | Constructor and Description |
---|---|
protected |
ByteSink()
Constructor for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
CharSink |
asCharSink(java.nio.charset.Charset charset)
Returns a
CharSink view of this ByteSink that writes characters to this sink as
bytes encoded with the given charset . |
java.io.OutputStream |
openBufferedStream()
Opens a new buffered
OutputStream for writing to this sink. |
abstract java.io.OutputStream |
openStream()
Opens a new
OutputStream for writing to this sink. |
void |
write(byte[] bytes)
Writes all the given bytes to this sink.
|
long |
writeFrom(java.io.InputStream input)
Writes all the bytes from the given
InputStream to this sink. |
protected ByteSink()
public CharSink asCharSink(java.nio.charset.Charset charset)
CharSink
view of this ByteSink
that writes characters to this sink as
bytes encoded with the given charset
.public abstract java.io.OutputStream openStream() throws java.io.IOException
OutputStream
for writing to this sink. This method returns a new,
independent stream each time it is called.
The caller is responsible for ensuring that the returned stream is closed.
java.io.IOException
- if an I/O error occurs while opening the streampublic java.io.OutputStream openBufferedStream() throws java.io.IOException
OutputStream
for writing to this sink. The returned stream is not
required to be a BufferedOutputStream
in order to allow implementations to simply
delegate to openStream()
when the stream returned by that method does not benefit from
additional buffering (for example, a ByteArrayOutputStream
). This method returns a new,
independent stream each time it is called.
The caller is responsible for ensuring that the returned stream is closed.
java.io.IOException
- if an I/O error occurs while opening the streamBufferedOutputStream
)public void write(byte[] bytes) throws java.io.IOException
java.io.IOException
- if an I/O occurs while writing to this sink@CanIgnoreReturnValue public long writeFrom(java.io.InputStream input) throws java.io.IOException
InputStream
to this sink. Does not close input
.java.io.IOException
- if an I/O occurs while reading from input
or writing to this sinkCopyright © 2010–2021. All rights reserved.