Search in sources :

Example 21 with Hasher

use of com.google.common.hash.Hasher in project gradle by gradle.

the class DefaultClasspathEntryHasher method hashZipEntry.

private HashCode hashZipEntry(InputStream inputStream, ZipEntry zipEntry, ClasspathContentHasher classpathContentHasher) throws IOException {
    Hasher hasher = new TrackingHasher(Hashing.md5().newHasher());
    classpathContentHasher.appendContent(zipEntry.getName(), inputStream, hasher);
    return hasher.hash();
}
Also used : Hasher(com.google.common.hash.Hasher)

Example 22 with Hasher

use of com.google.common.hash.Hasher in project gradle by gradle.

the class ExternalRepositoryResourceAccessor method withResource.

@Override
public void withResource(String relativePath, Action<? super InputStream> action) {
    try {
        String scheme = rootUri.getScheme();
        String host = rootUri.getHost();
        String path = makePath(rootUri.getPath());
        int port = rootUri.getPort();
        String userInfo = rootUri.getUserInfo();
        URI uri = new URI(scheme, userInfo, host, port, path + relativePath, null, null);
        Hasher hasher = Hashing.sha1().newHasher().putString(uri.toASCIIString(), Charsets.UTF_8);
        final String key = hasher.hash().toString();
        LocallyAvailableExternalResource resource = resourceAccessor.getResource(uri, new CacheAwareExternalResourceAccessor.ResourceFileStore() {

            @Override
            public LocallyAvailableResource moveIntoCache(File downloadedResource) {
                return fileStore.move(key, downloadedResource);
            }
        }, null);
        if (resource != null) {
            resource.withContent(action);
        }
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : Hasher(com.google.common.hash.Hasher) LocallyAvailableResource(org.gradle.internal.resource.local.LocallyAvailableResource) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource) URI(java.net.URI) CacheAwareExternalResourceAccessor(org.gradle.internal.resource.transfer.CacheAwareExternalResourceAccessor) File(java.io.File) UncheckedException(org.gradle.internal.UncheckedException)

Example 23 with Hasher

use of com.google.common.hash.Hasher in project riposte by Nike-Inc.

the class VerifyMultipartRequestsWorkComponentTest method getHashForMultipartPayload.

private static String getHashForMultipartPayload(String name, String filename, byte[] payloadBytes) {
    Hasher hasher = hashFunction.newHasher().putString(name, Charsets.UTF_8);
    if (filename != null)
        hasher = hasher.putString(filename, Charsets.UTF_8);
    hasher = hasher.putBytes(payloadBytes);
    HashCode hc = hasher.hash();
    return hc.toString();
}
Also used : Hasher(com.google.common.hash.Hasher) HashCode(com.google.common.hash.HashCode)

Example 24 with Hasher

use of com.google.common.hash.Hasher in project riposte by Nike-Inc.

the class VerifyPayloadHandlingComponentTest method getHashForPayload.

/**
     * @return The MD5 hash of the given payload. This can be used to verify correctness when sending payloads across the wire.
     */
private static String getHashForPayload(byte[] payloadBytes) {
    Hasher hasher = hashFunction.newHasher();
    hasher = hasher.putBytes(payloadBytes);
    HashCode hc = hasher.hash();
    return hc.toString();
}
Also used : Hasher(com.google.common.hash.Hasher) HashCode(com.google.common.hash.HashCode)

Example 25 with Hasher

use of com.google.common.hash.Hasher in project phoenix by apache.

the class SkipScanFilter method hashCode.

@Override
public int hashCode() {
    HashFunction hf = Hashing.goodFastHash(32);
    Hasher h = hf.newHasher();
    h.putInt(slots.size());
    for (int i = 0; i < slots.size(); i++) {
        h.putInt(slots.get(i).size());
        for (int j = 0; j < slots.size(); j++) {
            h.putBytes(slots.get(i).get(j).getLowerRange());
            h.putBytes(slots.get(i).get(j).getUpperRange());
        }
    }
    return h.hash().asInt();
}
Also used : Hasher(com.google.common.hash.Hasher) HashFunction(com.google.common.hash.HashFunction)

Aggregations

Hasher (com.google.common.hash.Hasher)59 IOException (java.io.IOException)10 Test (org.junit.Test)9 HashCode (com.google.common.hash.HashCode)8 InputStream (java.io.InputStream)5 Map (java.util.Map)5 BuildTarget (com.facebook.buck.model.BuildTarget)4 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)4 SettableFakeClock (com.facebook.buck.timing.SettableFakeClock)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 HashFunction (com.google.common.hash.HashFunction)3 OutputStream (java.io.OutputStream)3 Path (java.nio.file.Path)3 SimplePerfEvent (com.facebook.buck.event.SimplePerfEvent)2 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)2 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)2 BuildRuleType (com.facebook.buck.rules.BuildRuleType)2 Cell (com.facebook.buck.rules.Cell)2 ParamInfoException (com.facebook.buck.rules.ParamInfoException)2