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