public abstract class ByteSink extends Object implements OutputSupplier<OutputStream>
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(Charset charset)
|
OutputStream |
getOutput()
Deprecated.
This method is only provided for temporary compatibility with the
OutputSupplier interface and should not be called directly. Use
openStream() instead. This method is scheduled for removal in Guava 18.0. |
OutputStream |
openBufferedStream()
Opens a new buffered
OutputStream for writing to this sink. |
abstract 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(InputStream input)
Writes all the bytes from the given
InputStream to this sink. |
protected ByteSink()
public CharSink asCharSink(Charset charset)
public abstract OutputStream openStream() throws IOException
OutputStream for writing to this sink. This method should return a new,
independent stream each time it is called.
The caller is responsible for ensuring that the returned stream is closed.
IOException - if an I/O error occurs in the process of opening the stream@Deprecated public final OutputStream getOutput() throws IOException
OutputSupplier interface and should not be called directly. Use
openStream() instead. This method is scheduled for removal in Guava 18.0.getOutput in interface OutputSupplier<OutputStream>IOExceptionpublic OutputStream openBufferedStream() throws 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 should
return a new, independent stream each time it is called.
The caller is responsible for ensuring that the returned stream is closed.
IOException - if an I/O error occurs in the process of opening the streamBufferedOutputStream)public void write(byte[] bytes) throws IOException
IOException - if an I/O occurs in the process of writing to this sinkpublic long writeFrom(InputStream input) throws IOException
InputStream to this sink. Does not close
input.IOException - if an I/O occurs in the process of reading from input or writing to
this sinkCopyright © 2010-2014. All Rights Reserved.