HashingSink

expect 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();

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();
actual class HashingSink : Sink

Types

Link copied to clipboard
expect object Companion
actual object Companion
actual object Companion

Properties

Link copied to clipboard
@get:JvmName(name = "delegate")
val delegate: Sink

Sink to which this instance is delegating.

Link copied to clipboard
expect val hash: ByteString

Returns the hash of the bytes accepted thus far and resets the internal state of this sink.

@get:JvmName(name = "hash")
actual val hash: ByteString

Returns the hash of the bytes accepted thus far and resets the internal state of this sink.

actual val hash: ByteString

Returns the hash of the bytes accepted thus far and resets the internal state of this sink.

Functions

Link copied to clipboard

Returns a new sink that buffers writes to sink. The returned sink will batch writes to sink. Use this wherever you write to a sink to get an ergonomic and efficient access to data.

Link copied to clipboard

Returns a sink that uses cipher to encrypt or decrypt this.

close
Link copied to clipboard
expect abstract override fun close()

Pushes all buffered bytes to their final destination and releases the resources held by this sink. It is an error to write a closed sink. It is safe to close a sink more than once.

open override fun close()
open override fun close()
Link copied to clipboard
inline fun Sink.deflate(deflater: Deflater = Deflater()): DeflaterSink

Returns an DeflaterSink that DEFLATE-compresses data to this Sink while writing.

flush
Link copied to clipboard
expect abstract fun flush()

Pushes all buffered bytes to their final destination.

open override fun flush()
open override fun flush()
Link copied to clipboard
inline fun Sink.gzip(): GzipSink

Returns a GzipSink that gzip-compresses to this Sink while writing.

Link copied to clipboard

Returns a sink that uses digest to hash this.

Returns a sink that uses mac to hash this.

timeout
Link copied to clipboard
expect abstract fun timeout(): Timeout

Returns the timeout for this sink.

open override fun timeout(): Timeout
open override fun timeout(): Timeout
Link copied to clipboard
open override fun toString(): String
write
Link copied to clipboard
expect abstract fun write(source: Buffer, byteCount: Long)

Removes byteCount bytes from source and appends them to this.

open override fun write(source: Buffer, byteCount: Long)
open override fun write(source: Buffer, byteCount: Long)