List of usage examples for com.google.common.hash Hashing md5
public static HashFunction md5()
From source file:com.dangdang.ddframe.job.internal.reg.RegistryCenterFactory.java
/** * .//from w w w. jav a2s . c o m * * @param connectString * @param namespace ?? * @param digest ? * @return */ public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(final String connectString, final String namespace, final Optional<String> digest) { Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8).putString(namespace, Charsets.UTF_8); if (digest.isPresent()) { hasher.putString(digest.get(), Charsets.UTF_8); } HashCode hashCode = hasher.hash(); if (registryCenterMap.containsKey(hashCode)) { return registryCenterMap.get(hashCode); } ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace); if (digest.isPresent()) { zkConfig.setDigest(digest.get()); } CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(zkConfig); result.init(); registryCenterMap.putIfAbsent(hashCode, result); return result; }
From source file:com.streamsets.pipeline.lib.hashing.HashingUtil.java
public static HashFunction getHasher(String hashAlgorithm) { switch (hashAlgorithm) { case "murmur3_128": return Hashing.murmur3_128(); case "MD5": return Hashing.md5(); case "SHA-1": return Hashing.sha1(); case "SHA-256": return Hashing.sha256(); default:// w w w. java2 s. c o m throw new IllegalArgumentException(Utils.format("Unsupported Hashing Algorithm: {}", hashAlgorithm)); } }
From source file:com.mac.abstractrepository.db.common.IdGenerator.java
public default void generateId(Field idField, String... values) throws IllegalArgumentException, IllegalAccessException { if (Objects.nonNull(idField) && Objects.nonNull(values) && values.length > 0) { Class<?> type = idField.getType(); if (type == String.class) { HashFunction hf = Hashing.md5(); Hasher hasher = hf.newHasher(); for (String str : values) { if (Objects.isNull(str) || str.isEmpty()) { return; }// www.j ava 2s.c o m hasher.putString(str, Charsets.UTF_8); } HashCode hc = hasher.hash(); String hash = hc.toString(); if (Objects.isNull(hash)) { return; } idField.setAccessible(true); idField.set(this, hash); idField.setAccessible(false); } } }
From source file:com.dangdang.ddframe.job.lite.lifecycle.internal.reg.RegistryCenterFactory.java
/** * .//from w w w . j av a 2 s. c o m * * @param connectString * @param namespace ?? * @param digest ? * @return */ public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(final String connectString, final String namespace, final Optional<String> digest) { Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8).putString(namespace, Charsets.UTF_8); if (digest.isPresent()) { hasher.putString(digest.get(), Charsets.UTF_8); } HashCode hashCode = hasher.hash(); CoordinatorRegistryCenter result = REG_CENTER_REGISTRY.get(hashCode); if (null != result) { return result; } ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace); if (digest.isPresent()) { zkConfig.setDigest(digest.get()); } result = new ZookeeperRegistryCenter(zkConfig); result.init(); REG_CENTER_REGISTRY.put(hashCode, result); return result; }
From source file:lumbermill.Fingerprint.java
/** * Creates an MD5 hash based on the configured source string and stores it as * metadata under the field name 'fingerprint' (using same name as logstash). * * It is up to the user to create the source string to be used as fingerprint. * Best practice to separate each 'word' with a char, like a pipe (|) char to prevent * any unexpected behaviour. Read more at https://github.com/google/guava/wiki/HashingExplained. * * <pre>/*from w w w . j av a 2s . c o m*/ * * Groovy usage that creates a hash from two fields: * {@code * fingerprint.md5 ('{message}|{@timestamp}') * } * </pre> */ public static <E extends Event> Func1<E, Observable<E>> md5(String sourcePattern) { StringTemplate template = StringTemplate.compile(sourcePattern); return e -> { String sourceValue = template.format(e).get(); String hashAsHex = Hashing.md5().hashString(sourceValue, Charsets.UTF_8).toString(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Fingerprint of {} => {}", sourceValue, hashAsHex); } // as Metadata return e.put("fingerprint", hashAsHex).toObservable(); }; }
From source file:org.gradle.api.internal.hash.DefaultFileHasher.java
private static Hasher createFileHasher() { Hasher hasher = Hashing.md5().newHasher(); hasher.putBytes(SIGNATURE); return hasher; }
From source file:org.gradle.internal.hash.DefaultFileContentHasherFactory.java
@Override public Hasher create() { Hasher hasher = Hashing.md5().newHasher(); hasher.putBytes(SIGNATURE); return hasher; }
From source file:documents.Document.java
public int hashCode() { Hasher hf = Hashing.md5().newHasher(); metadata.forEach((k, v) -> hf.putString(v, Charset.defaultCharset())); return hf.hash().asInt(); }
From source file:co.cask.tigon.internal.app.runtime.flow.FlowUtils.java
/** * Generates a queue consumer groupId for the given flowlet in the given program id. *//*from w w w .j a v a 2 s. c o m*/ public static long generateConsumerGroupId(String flowId, String flowletId) { return Hashing.md5().newHasher().putString(flowId).putString(flowletId).hash().asLong(); }
From source file:ome.util.checksum.MD5ChecksumProviderImpl.java
public MD5ChecksumProviderImpl() { super(Hashing.md5()); }