Hashing 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();
Types
Properties
Functions
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.
Returns a source that uses cipher to encrypt or decrypt this.
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.
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.
Returns a GzipSource that gzip-decompresses this Source while reading.
Returns an InflaterSource that DEFLATE-decompresses this Source while reading.
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.
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.