本文整理了Java中com.google.common.hash.Hashing.crc32()
方法的一些代码示例,展示了Hashing.crc32()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hashing.crc32()
方法的具体详情如下:
包路径:com.google.common.hash.Hashing
类名称:Hashing
方法名:crc32
[英]Returns a hash function implementing the CRC-32 checksum algorithm (32 hash bits).
To get the long value equivalent to Checksum#getValue() for a HashCode produced by this function, use HashCode#padToLong().
This function is best understood as a checksum rather than a true hash function.
[中]返回实现CRC-32校验和算法的哈希函数(32个哈希位)。
要获取此函数生成的HashCode的与Checksum#getValue()等价的长值,请使用HashCode#padToLong()。
最好将此函数理解为checksum,而不是真正的hash function。
代码示例来源:origin: Graylog2/graylog2-server
@Override
protected String getDigest(String value) {
return Hashing.crc32().hashString(value, StandardCharsets.UTF_8).toString();
}
代码示例来源:origin: google/guava
public void testCrc32() {
HashTestUtils.assertInvariants(Hashing.crc32());
assertEquals("Hashing.crc32()", Hashing.crc32().toString());
}
代码示例来源:origin: Netflix/EVCache
hf = Hashing.crc32();
break;
代码示例来源:origin: omero/common
protected CRC32ChecksumProviderImpl() {
super(Hashing.crc32());
}
代码示例来源:origin: com.android.tools.build/builder
/**
* Computes the hashcode of the cached file.
*
* @return the hash code
*/
@Nullable
private HashCode hashFile() {
try {
return Files.hash(mFile, Hashing.crc32());
} catch (IOException e) {
return null;
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Override
public ToStringHelper string() {
ToStringHelper toString = super.string();
if (groupNames.size() != 0)
toString.add("groupNames", groupNames);
if (noKeyPair)
toString.add("noKeyPair", noKeyPair);
toString.add("keyPair", keyPair);
if (userData != null && userData.size() > 0)
toString.add("userDataCksum", Hashing.crc32().hashBytes(Bytes.toArray(userData)));
ImmutableSet<BlockDeviceMapping> mappings = blockDeviceMappings.build();
if (mappings.size() != 0)
toString.add("blockDeviceMappings", mappings);
return toString;
}
代码示例来源:origin: org.jclouds.api/ec2
@Override
public ToStringHelper string() {
ToStringHelper toString = super.string();
if (groupNames.size() != 0)
toString.add("groupNames", groupNames);
if (noKeyPair)
toString.add("noKeyPair", noKeyPair);
toString.add("keyPair", keyPair);
if (userData != null && userData.size() > 0)
toString.add("userDataCksum", Hashing.crc32().hashBytes(Bytes.toArray(userData)));
ImmutableSet<BlockDeviceMapping> mappings = blockDeviceMappings.build();
if (mappings.size() != 0)
toString.add("blockDeviceMappings", mappings);
return toString;
}
代码示例来源:origin: com.amysta.jclouds.api/ec2
@Override
public ToStringHelper string() {
ToStringHelper toString = super.string();
if (!groupNames.isEmpty())
toString.add("groupNames", groupNames);
if (noKeyPair)
toString.add("noKeyPair", noKeyPair);
toString.add("keyPair", keyPair);
if (userData != null && !userData.isEmpty())
toString.add("userDataCksum", Hashing.crc32().hashBytes(Bytes.toArray(userData)));
ImmutableSet<BlockDeviceMapping> mappings = blockDeviceMappings.build();
if (!mappings.isEmpty())
toString.add("blockDeviceMappings", mappings);
if (maxCount != null && maxCount.intValue() > 0)
toString.add("maxCount", maxCount);
if (clientToken != null)
toString.add("clientToken", clientToken);
return toString;
}
代码示例来源:origin: apache/jclouds
@Override
public ToStringHelper string() {
ToStringHelper toString = super.string();
if (!groupNames.isEmpty())
toString.add("groupNames", groupNames);
if (noKeyPair)
toString.add("noKeyPair", noKeyPair);
toString.add("keyPair", keyPair);
if (userData != null && !userData.isEmpty())
toString.add("userDataCksum", Hashing.crc32().hashBytes(Bytes.toArray(userData)));
ImmutableSet<BlockDeviceMapping> mappings = blockDeviceMappings.build();
if (!mappings.isEmpty())
toString.add("blockDeviceMappings", mappings);
if (maxCount != null && maxCount.intValue() > 0)
toString.add("maxCount", maxCount);
if (clientToken != null)
toString.add("clientToken", clientToken);
return toString;
}
代码示例来源:origin: molgenis/molgenis
private String createFingerprint(Class<?> contextClass, String resourceName) throws IOException {
byte[] bytes =
contextClass != null
? ResourceUtils.getBytes(contextClass, resourceName)
: ResourceUtils.getBytes(resourceName);
HashCode crc32 = Hashing.crc32().hashBytes(bytes);
return Base64.getUrlEncoder().withoutPadding().encodeToString(crc32.asBytes());
}
}
代码示例来源:origin: indeedeng/util
public static long computeFileChecksum(@Nonnull final File file, @Nonnull final Checksum checksum) throws IOException {
return ByteStreams.hash(com.google.common.io.Files.newInputStreamSupplier(file), Hashing.crc32())
.padToLong();
}
代码示例来源:origin: org.molgenis/molgenis-core
private String createFingerprint(Class<?> contextClass, String resourceName) throws IOException {
byte[] bytes =
contextClass != null
? ResourceUtils.getBytes(contextClass, resourceName)
: ResourceUtils.getBytes(resourceName);
HashCode crc32 = Hashing.crc32().hashBytes(bytes);
return BaseEncoding.base64Url().omitPadding().encode(crc32.asBytes());
}
}
代码示例来源:origin: com.conveyal/r5
/**
* FIXME why is this a long when crc32 returns an int?
* @return a checksum of the graph, for use in verifying whether it changed or remained the same after
* some operation.
*/
public long checksum () {
LOG.info("Calculating transport network checksum...");
try {
File tempFile = File.createTempFile("r5-network-checksum-", ".dat");
tempFile.deleteOnExit();
KryoNetworkSerializer.write(this, tempFile);
HashCode crc32 = Files.hash(tempFile, Hashing.crc32());
tempFile.delete();
LOG.info("Network CRC is {}", crc32.hashCode());
return crc32.hashCode();
} catch (IOException e) {
throw new RuntimeException();
}
}
代码示例来源:origin: org.molgenis/molgenis-core-ui
private String createFingerprint(String themeUri) throws IOException, MolgenisStyleException {
String fileName = extractThemeNameFromThemeUri(themeUri);
BootstrapVersion version = extractBootstrapVersionFromPath(themeUri);
FileSystemResource styleData = styleService.getThemeData(fileName, version);
byte[] bytes = IOUtils.toByteArray(styleData.getInputStream());
HashCode crc32 = Hashing.crc32().hashBytes(bytes);
return BaseEncoding.base64Url().omitPadding().encode(crc32.asBytes());
}
代码示例来源:origin: com.google.guava/guava-tests
public void testCrc32() {
HashTestUtils.assertInvariants(Hashing.crc32());
assertEquals("Hashing.crc32()", Hashing.crc32().toString());
}
代码示例来源:origin: com.google.guava/guava-tests
private byte runHashFunction(int reps, HashFunction hashFunction) {
byte result = 0x01;
// Trick the JVM to prevent it from using the hash function non-polymorphically
result ^= Hashing.crc32().hashInt(reps).asBytes()[0];
result ^= Hashing.adler32().hashInt(reps).asBytes()[0];
for (int i = 0; i < reps; i++) {
result ^= hashFunction.hashBytes(testBytes).asBytes()[0];
}
return result;
}
}
代码示例来源:origin: com.android.tools.build/builder
private static void configureStoredEntry(JarEntry entry, File inputFile) throws IOException {
ByteSource byteSource = Files.asByteSource(inputFile);
long size = inputFile.length();
entry.setMethod(ZipEntry.STORED);
entry.setSize(size);
entry.setCompressedSize(size);
entry.setCrc(byteSource.hash(Hashing.crc32()).padToLong());
}
代码示例来源:origin: com.google.guava/guava-tests
@Benchmark byte crc32HashFunction(int reps) {
return runHashFunction(reps, Hashing.crc32());
}
代码示例来源:origin: com.yahoo.pulsar/pulsar-broker
/**
* Default constructor.
*
* @throws PulsarServerException
*/
public NamespaceService(PulsarService pulsar) {
this.pulsar = pulsar;
host = pulsar.getAdvertisedAddress();
this.config = pulsar.getConfiguration();
this.loadManager = pulsar.getLoadManager();
ServiceUnitZkUtils.initZK(pulsar.getLocalZkCache().getZooKeeper(), pulsar.getBrokerServiceUrl());
this.bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
this.ownershipCache = new OwnershipCache(pulsar, bundleFactory);
}
代码示例来源:origin: org.apache.pulsar/pulsar-broker
/**
* Default constructor.
*
* @throws PulsarServerException
*/
public NamespaceService(PulsarService pulsar) {
this.pulsar = pulsar;
host = pulsar.getAdvertisedAddress();
this.config = pulsar.getConfiguration();
this.loadManager = pulsar.getLoadManager();
ServiceUnitZkUtils.initZK(pulsar.getLocalZkCache().getZooKeeper(), pulsar.getBrokerServiceUrl());
this.bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
this.ownershipCache = new OwnershipCache(pulsar, bundleFactory);
this.namespaceClients = new ConcurrentOpenHashMap<>();
}
内容来源于网络,如有侵权,请联系作者删除!