HashingSink

class HashingSink : Sink

A sink that computes a hash of the full stream of bytes it has accepted. To use, create an instance with your preferred hash algorithm. Write all of the data to the sink and then call hash to compute the final hash value.

In this example we use HashingSink with a BufferedSink to make writing to the sink easier.

HashingSink hashingSink = HashingSink.sha256(s);
BufferedSink bufferedSink = Okio.buffer(hashingSink);

... // Write to bufferedSink and either flush or close it.

ByteString hash = hashingSink.hash();
class HashingSink : ForwardingSink, Sink

A sink that computes a hash of the full stream of bytes it has accepted. To use, create an instance with your preferred hash algorithm. Write all of the data to the sink and then call hash to compute the final hash value.

In this example we use HashingSink with a BufferedSink to make writing to the sink easier.

HashingSink hashingSink = HashingSink.sha256(s);
BufferedSink bufferedSink = Okio.buffer(hashingSink);

... // Write to bufferedSink and either flush or close it.

ByteString hash = hashingSink.hash();

Types

Companion
Link copied to clipboard
common
object Companion

Functions

close
Link copied to clipboard
open override fun close()
common
abstract override fun close()
Pushes all buffered bytes to their final destination and releases the resources held by this sink.
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
open operator fun equals(other: Any?): Boolean
flush
Link copied to clipboard
open override fun flush()
common
abstract fun flush()
Pushes all buffered bytes to their final destination.
hashCode
Link copied to clipboard
open fun hashCode(): Int
open fun hashCode(): Int
timeout
Link copied to clipboard
open override fun timeout(): Timeout
common
abstract fun timeout(): Timeout
Returns the timeout for this sink.
toString
Link copied to clipboard
open fun toString(): String
open override fun toString(): String
write
Link copied to clipboard
open override fun write(source: Buffer, byteCount: Long)
common
abstract fun write(source: Buffer, byteCount: Long)
Removes byteCount bytes from source and appends them to this.

Properties

delegate
Link copied to clipboard
val delegate: Sink
Sink to which this instance is delegating.
hash
Link copied to clipboard
val hash: ByteString
Returns the hash of the bytes accepted thus far and resets the internal state of this sink.
val hash: ByteString
Returns the hash of the bytes accepted thus far and resets the internal state of this sink.