public interface Sink
extends java.io.Closeable, java.io.Flushable
Most application code shouldn't operate on a sink directly, but rather on a
BufferedSink
which is both more efficient and more convenient. Use
Okio.buffer(Sink)
to wrap any sink with a buffer.
Sinks are easy to test: just use a Buffer
in your tests, and
read from it to confirm it received the data that was expected.
OutputStream
.
OutputStream
requires multiple layers when emitted data is
heterogeneous: a DataOutputStream
for primitive values, a BufferedOutputStream
for buffering, and OutputStreamWriter
for
charset encoding. This class uses BufferedSink
for all of the above.
Sink is also easier to layer: there is no single-byte write method that is awkward to implement efficiently.
Okio.sink(java.io.OutputStream)
to adapt an OutputStream
to a sink. Use BufferedSink.outputStream()
to adapt a sink to an OutputStream
.Modifier and Type | Method and Description |
---|---|
void |
close()
Pushes all buffered bytes to their final destination and releases the
resources held by this sink.
|
void |
flush()
Pushes all buffered bytes to their final destination.
|
Timeout |
timeout()
Returns the timeout for this sink.
|
void |
write(Buffer source,
long byteCount)
Removes
byteCount bytes from source and appends them to this. |
void write(Buffer source, long byteCount) throws java.io.IOException
byteCount
bytes from source
and appends them to this.java.io.IOException
void flush() throws java.io.IOException
flush
in interface java.io.Flushable
java.io.IOException
Timeout timeout()
void close() throws java.io.IOException
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
java.io.IOException
Copyright © 2018. All Rights Reserved.