HashingSource

class HashingSource : Source

A source that computes a hash of the full stream of bytes it has supplied. To use, create an instance with your preferred hash algorithm. Exhaust the source by reading all of its bytes and then call hash to compute the final hash value.

In this example we use HashingSource with a BufferedSource to make reading from the source easier.

HashingSource hashingSource = HashingSource.sha256(rawSource);
BufferedSource bufferedSource = Okio.buffer(hashingSource);

... // Read all of bufferedSource.

ByteString hash = hashingSource.hash();
class HashingSource : ForwardingSource, Source

A source that computes a hash of the full stream of bytes it has supplied. To use, create an instance with your preferred hash algorithm. Exhaust the source by reading all of its bytes and then call hash to compute the final hash value.

In this example we use HashingSource with a BufferedSource to make reading from the source easier.

HashingSource hashingSource = HashingSource.sha256(rawSource);
BufferedSource bufferedSource = Okio.buffer(hashingSource);

... // Read all of bufferedSource.

ByteString hash = hashingSource.hash();

Types

Companion
Link copied to clipboard
common
object Companion

Functions

close
Link copied to clipboard
open override fun close()
Closes this source and releases the resources held by this source.
common
abstract override fun close()
Closes this source and releases the resources held by this source.
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
open operator fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
open fun hashCode(): Int
open fun hashCode(): Int
read
Link copied to clipboard
open override fun read(sink: Buffer, byteCount: Long): Long
Removes at least 1, and up to byteCount bytes from this and appends them to sink.
common
abstract fun read(sink: Buffer, byteCount: Long): Long
Removes at least 1, and up to byteCount bytes from this and appends them to sink.
timeout
Link copied to clipboard
open override fun timeout(): Timeout
Returns the timeout for this source.
common
abstract fun timeout(): Timeout
Returns the timeout for this source.
toString
Link copied to clipboard
open fun toString(): String
open override fun toString(): String

Properties

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