List of usage examples for com.google.common.hash Hasher hash
@CheckReturnValue HashCode hash();
From source file:org.locationtech.geogig.plumbing.HashObject.java
/** * Hashes a RevObject using a SHA1 hasher. * /*from w w w .ja v a 2s .c om*/ * @return a new ObjectId created from the hash of the RevObject. */ @Override protected ObjectId _call() { Preconditions.checkState(object != null, "Object has not been set."); final Hasher hasher = ObjectId.HASH_FUNCTION.newHasher(); @SuppressWarnings("unchecked") final Funnel<RevObject> funnel = (Funnel<RevObject>) FUNNELS[object.getType().value()]; funnel.funnel(object, hasher); final byte[] rawKey = hasher.hash().asBytes(); final ObjectId id = ObjectId.createNoClone(rawKey); return id; }
From source file:org.fim.model.State.java
public String hashState() { HashFunction hashFunction = Hashing.sha512(); Hasher hasher = hashFunction.newHasher(Constants._10_MB); hashObject(hasher);//from w w w. j ava 2 s.co m HashCode hash = hasher.hash(); return hash.toString(); }
From source file:com.spotify.heroic.cache.memcached.MemcachedQueryCache.java
private String buildCacheKey(final FullQuery.Request request) { final Hasher hasher = HASH_FUNCTION.newHasher(); request.hashTo(new ObjectHasher(hasher)); return PREFIX + hasher.hash().toString(); }
From source file:org.openmicroscopy.shoola.keywords.ThumbnailCheckLibrary.java
/** * <table>/* w w w. j a v a 2 s . co m*/ * <td>Get Thumbnail Hash</td> * <td>name of image whose thumbnail is queried</td> * </table> * @param imageFilename the name of the image * @return the hash of the thumbnail canvas image * @throws MultipleComponentsFoundException if multiple thumbnails exist for the given name * @throws ComponentNotFoundException if no thumbnails exist for the given name */ public String getThumbnailHash(String imageFilename) throws ComponentNotFoundException, MultipleComponentsFoundException { final RenderedImage image = captureImage("thumbnail", imageFilename); final IteratorIntPixel pixels = new IteratorIntPixel(image); final Hasher hasher = Hashing.goodFastHash(128).newHasher(); while (pixels.hasNext()) { hasher.putInt(pixels.next()); } return hasher.hash().toString(); }
From source file:io.divolte.server.ShortTermDuplicateMemory.java
/** * Query whether an event has been seen before or not, based on event properties. * @param eventProperties An array of values that are specific to the event. * @return <code>true</code> if we have probably seen this event previously, or * false otherwise.//ww w . ja va2 s .c om */ public boolean isProbableDuplicate(final String... eventProperties) { final Hasher hasher = HASHING_FUNCTION.newHasher(); for (final String eventProperty : eventProperties) { hasher.putString(eventProperty, StandardCharsets.UTF_8); } return isProbablyDuplicate(hasher.hash()); }
From source file:org.gradle.api.internal.changedetection.state.DefaultClasspathEntryHasher.java
private HashCode hashFile(FileDetails fileDetails, Hasher hasher, ClasspathContentHasher classpathContentHasher) { try {/*from w ww . jav a 2 s .c o m*/ byte[] content = Files.toByteArray(new File(fileDetails.getPath())); if (classpathContentHasher.updateHash(fileDetails, hasher, content)) { return hasher.hash(); } return null; } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.spotify.heroic.aggregation.cardinality.ExactCardinalityBucket.java
@Override public void update(final Map<String, String> key, final Metric d) { final Hasher hasher = HASH_FUNCTION.newHasher(); if (includeKey) { for (final String k : KEY_ORDER.sortedCopy(key.keySet())) { hasher.putString(k, Charsets.UTF_8).putString(key.get(k), Charsets.UTF_8); }//from ww w .ja v a 2s . c o m } d.hash(hasher); if (seen.add(hasher.hash())) { count.incrementAndGet(); } }
From source file:com.mac.holdempoker.app.impl.SimplePlayer.java
private void setPid(String... pidParts) { HashFunction hf = Hashing.md5();/*from ww w . j av a 2s.c om*/ Hasher hasher = hf.newHasher(); for (String str : pidParts) { hasher.putString(str, Charset.forName("UTF-8")); } HashCode hc = hasher.hash(); this.setPlayerId(hc.toString()); }
From source file:com.spotify.heroic.aggregation.cardinality.HyperLogLogCardinalityBucket.java
@Override public void update(final Map<String, String> key, final Metric d) { final Hasher hasher = HASH_FUNCTION.newHasher(); if (includeKey) { for (final String k : KEY_ORDER.sortedCopy(key.keySet())) { hasher.putString(k, Charsets.UTF_8).putString(key.get(k), Charsets.UTF_8); }// w w w . ja v a 2 s . c om } d.hash(hasher); final long hash = hasher.hash().asLong(); seen.offerHashed(hash); }
From source file:org.apache.flink.streaming.api.graph.StreamGraphHasherV2.java
/** * Generates a hash from a user-specified ID. *//*w w w . j a va2s . co m*/ private byte[] generateUserSpecifiedHash(StreamNode node, Hasher hasher) { hasher.putString(node.getTransformationUID(), Charset.forName("UTF-8")); return hasher.hash().asBytes(); }