HashingSource

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

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();
actual class HashingSource : Source

Types

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

Properties

Link copied to clipboard
expect val hash: ByteString

Returns the hash of the bytes supplied thus far and resets the internal state of this source.

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

Returns the hash of the bytes supplied thus far and resets the internal state of this source.

actual val hash: ByteString

Functions

Link copied to clipboard

Returns a new source that buffers reads from source. The returned source will perform bulk reads into its in-memory buffer. Use this wherever you read a source to get an ergonomic and efficient access to data.

Link copied to clipboard

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

close
Link copied to clipboard
abstract override fun close()

Closes this source and releases the resources held by this source. It is an error to read a closed source. It is safe to close a source more than once.

open override fun close()

Closes this source and releases the resources held by this source. It is an error to read a closed source. It is safe to close a source more than once.

Link copied to clipboard
inline fun Source.gzip(): GzipSource

Returns a GzipSource that gzip-decompresses this Source while reading.

Link copied to clipboard

Returns a source that uses digest to hash this.

Returns a source that uses mac to hash this.

Link copied to clipboard
inline fun Source.inflate(inflater: Inflater = Inflater()): InflaterSource

Returns an InflaterSource that DEFLATE-decompresses this Source while reading.

read
Link copied to clipboard
abstract fun read(sink: Buffer, byteCount: Long): Long

Removes at least 1, and up to byteCount bytes from this and appends them to sink. Returns the number of bytes read, or -1 if this source is exhausted.

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. Returns the number of bytes read, or -1 if this source is exhausted.

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. Returns the number of bytes read, or -1 if this source is exhausted.

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

Returns the timeout for this source.

open override fun timeout(): Timeout

Returns the timeout for this source.