本文整理了Java中com.google.common.hash.Hashing.crc32c()
方法的一些代码示例,展示了Hashing.crc32c()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hashing.crc32c()
方法的具体详情如下:
包路径:com.google.common.hash.Hashing
类名称:Hashing
方法名:crc32c
[英]Returns a hash function implementing the CRC32C checksum algorithm (32 hash bits) as described by RFC 3720, Section 12.1.
This function is best understood as a checksum rather than a true hash function.
[中]返回实现CRC32C校验和算法(32个哈希位)的哈希函数,如RFC 3720第12.1节所述。
最好将此函数理解为checksum,而不是真正的hash function。
代码示例来源:origin: Graylog2/graylog2-server
@Override
protected String getDigest(String value) {
return Hashing.crc32c().hashString(value, StandardCharsets.UTF_8).toString();
}
代码示例来源:origin: google/guava
/**
* Verifies that the crc of an array of byte data matches the expected value.
*
* @param expectedCrc the expected crc value.
* @param data the data to run the checksum on.
*/
private static void assertCrc(int expectedCrc, byte[] data) {
int actualCrc = Hashing.crc32c().hashBytes(data).asInt();
assertEquals(expectedCrc, actualCrc);
}
代码示例来源:origin: googleapis/google-cloud-java
@Override
public Blob create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options) {
content = firstNonNull(content, EMPTY_BYTE_ARRAY);
BlobInfo updatedInfo =
blobInfo
.toBuilder()
.setMd5(BaseEncoding.base64().encode(Hashing.md5().hashBytes(content).asBytes()))
.setCrc32c(
BaseEncoding.base64()
.encode(Ints.toByteArray(Hashing.crc32c().hashBytes(content).asInt())))
.build();
return internalCreate(updatedInfo, content, options);
}
代码示例来源:origin: google/google-api-java-client-samples
DigestOutputStream md5DigestOutputStream = new DigestOutputStream(
nullOutputStream, MessageDigest.getInstance("MD5"));
HashingOutputStream crc32cHashingOutputStream = new HashingOutputStream(Hashing.crc32c(),
md5DigestOutputStream);
ObjectsDownloadExample.downloadToOutputStream(storage, settings.getBucket(),
代码示例来源:origin: gentics/mesh
/**
* Hash the given key in order to generate a uniform etag hash.
*
* @param key
* Key which should be hashed
* @return Computed hash
*/
public static String hash(String key) {
return Hashing.crc32c().hashString(key.toString(), Charset.defaultCharset()).toString();
}
代码示例来源:origin: gentics/mesh
/**
* Hash the given int in order to generate a uniform etag hash.
*
* @param key
* Key which should be hashed
* @return Computed hash
*/
public static String hash(int key) {
return Hashing.crc32c().hashInt(key).toString();
}
代码示例来源:origin: CorfuDB/CorfuDB
/**
* Returns checksum used for log.
*
* @param bytes data over which to compute the checksum
* @return checksum of bytes
*/
static int getChecksum(byte[] bytes) {
Hasher hasher = Hashing.crc32c().newHasher();
for (byte a : bytes) {
hasher.putByte(a);
}
return hasher.hash().asInt();
}
代码示例来源:origin: CorfuDB/CorfuDB
public static int getChecksum(byte[] bytes) {
Hasher hasher = Hashing.crc32c().newHasher();
for (byte a : bytes) {
hasher.putByte(a);
}
return hasher.hash().asInt();
}
代码示例来源:origin: CorfuDB/CorfuDB
/**
* Returns checksum used for log.
* @param bytes data over which to compute the checksum
* @return checksum of bytes
*/
public static int getChecksum(byte[] bytes) {
Hasher hasher = Hashing.crc32c().newHasher();
for (byte a : bytes) {
hasher.putByte(a);
}
return hasher.hash().asInt();
}
代码示例来源:origin: CorfuDB/CorfuDB
static int getChecksum(int num) {
Hasher hasher = Hashing.crc32c().newHasher();
return hasher.putInt(num).hash().asInt();
}
}
代码示例来源:origin: CorfuDB/CorfuDB
static int getChecksum(long num) {
Hasher hasher = Hashing.crc32c().newHasher();
return hasher.putLong(num).hash().asInt();
}
代码示例来源:origin: CorfuDB/CorfuDB
static int getChecksum(int num) {
Hasher hasher = Hashing.crc32c().newHasher();
return hasher.putInt(num).hash().asInt();
}
代码示例来源:origin: com.google.gcloud/gcloud-java-storage
@Override
public Blob create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options) {
content = firstNonNull(content, EMPTY_BYTE_ARRAY);
BlobInfo updatedInfo = blobInfo.toBuilder()
.md5(BaseEncoding.base64().encode(Hashing.md5().hashBytes(content).asBytes()))
.crc32c(BaseEncoding.base64().encode(
Ints.toByteArray(Hashing.crc32c().hashBytes(content).asInt())))
.build();
return create(updatedInfo, new ByteArrayInputStream(content), options);
}
代码示例来源:origin: com.google.cloud/google-cloud-storage
@Override
public Blob create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options) {
content = firstNonNull(content, EMPTY_BYTE_ARRAY);
BlobInfo updatedInfo =
blobInfo
.toBuilder()
.setMd5(BaseEncoding.base64().encode(Hashing.md5().hashBytes(content).asBytes()))
.setCrc32c(
BaseEncoding.base64()
.encode(Ints.toByteArray(Hashing.crc32c().hashBytes(content).asInt())))
.build();
return internalCreate(updatedInfo, content, options);
}
代码示例来源:origin: com.google.guava/guava-tests
/**
* Verifies that the crc of an array of byte data matches the expected value.
*
* @param expectedCrc the expected crc value.
* @param data the data to run the checksum on.
*/
private static void assertCrc(int expectedCrc, byte[] data) {
int actualCrc = Hashing.crc32c().hashBytes(data).asInt();
assertEquals(expectedCrc, actualCrc);
}
代码示例来源:origin: com.google.cloud.bigdataoss/gcsio
@Override
public synchronized void close() throws IOException {
synchronized (InMemoryObjectEntry.this) {
completedContents = toByteArray();
HashCode md5 = Hashing.md5().hashBytes(completedContents);
HashCode crc32c = Hashing.crc32c().hashBytes(completedContents);
writeStream = null;
writeChannel = null;
info =
new GoogleCloudStorageItemInfo(
info.getResourceId(),
info.getCreationTime(),
/* size= */ completedContents.length,
/* location= */ null,
/* storageClass= */ null,
info.getContentType(),
info.getContentEncoding(),
info.getMetadata(),
/* contentGeneration= */ 1,
/* metaGeneration= */ 1,
new VerificationAttributes(md5.asBytes(), Ints.toByteArray(crc32c.asInt())));
}
}
};
内容来源于网络,如有侵权,请联系作者删除!