public final class HashingSource extends ForwardingSource
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();
| 限定符和类型 | 方法和说明 |
|---|---|
ByteString |
hash()
Returns the hash of the bytes supplied thus far and resets the internal state of this source.
|
static HashingSource |
hmacSha1(Source source,
ByteString key)
Returns a sink that uses the obsolete SHA-1 HMAC algorithm to produce 160-bit hashes.
|
static HashingSource |
hmacSha256(Source source,
ByteString key)
Returns a sink that uses the SHA-256 HMAC algorithm to produce 256-bit hashes.
|
static HashingSource |
md5(Source source)
Returns a sink that uses the obsolete MD5 hash algorithm to produce 128-bit hashes.
|
long |
read(Buffer sink,
long byteCount)
Removes at least 1, and up to
byteCount bytes from this and appends them to sink. |
static HashingSource |
sha1(Source source)
Returns a sink that uses the obsolete SHA-1 hash algorithm to produce 160-bit hashes.
|
static HashingSource |
sha256(Source source)
Returns a sink that uses the SHA-256 hash algorithm to produce 256-bit hashes.
|
close, delegate, timeout, toStringpublic static HashingSource md5(Source source)
public static HashingSource sha1(Source source)
public static HashingSource sha256(Source source)
public static HashingSource hmacSha1(Source source, ByteString key)
public static HashingSource hmacSha256(Source source, ByteString key)
public long read(Buffer sink, long byteCount) throws IOException
SourcebyteCount bytes from this and appends them to sink. Returns the number of bytes read, or -1 if this source is exhausted.read 在接口中 Sourceread 在类中 ForwardingSourceIOExceptionpublic final 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 supplied.
Copyright © 2025. All rights reserved.