public final class HashingSink extends ForwardingSink
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();
Modifier and Type | Method and Description |
---|---|
ByteString |
hash()
Returns the hash of the bytes accepted thus far and resets the internal state of this sink.
|
static HashingSink |
md5(Sink sink)
Returns a sink that uses the obsolete MD5 hash algorithm.
|
static HashingSink |
sha1(Sink sink)
Returns a sink that uses the obsolete SHA-1 hash algorithm.
|
static HashingSink |
sha256(Sink sink)
Returns a sink that uses the SHA-256 hash algorithm.
|
void |
write(Buffer source,
long byteCount)
Removes
byteCount bytes from source and appends them to this. |
public static HashingSink md5(Sink sink)
public static HashingSink sha1(Sink sink)
public static HashingSink sha256(Sink sink)
public void write(Buffer source, long byteCount) throws IOException
Sink
byteCount
bytes from source
and appends them to this.write
in interface Sink
write
in class ForwardingSink
IOException
public ByteString hash()
Warning: This method is not idempotent. Each time this method is called its internal state is cleared. This starts a new hash with zero bytes accepted.
Copyright © 2016. All Rights Reserved.