Search in sources :

Example 31 with Hasher

use of com.google.common.hash.Hasher in project paascloud-master by paascloud.

the class RegistryCenterFactory method createCoordinatorRegistryCenter.

/**
 * 创建注册中心.
 *
 * @param zookeeperProperties the zookeeper properties
 *
 * @return 注册中心对象 coordinator registry center
 */
public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(ZookeeperProperties zookeeperProperties) {
    Hasher hasher = Hashing.md5().newHasher().putString(zookeeperProperties.getZkAddressList(), Charsets.UTF_8);
    HashCode hashCode = hasher.hash();
    CoordinatorRegistryCenter result = REG_CENTER_REGISTRY.get(hashCode);
    if (null != result) {
        return result;
    }
    result = new ZookeeperRegistryCenter(zookeeperProperties);
    result.init();
    REG_CENTER_REGISTRY.put(hashCode, result);
    return result;
}
Also used : ZookeeperRegistryCenter(com.paascloud.core.registry.zookeeper.ZookeeperRegistryCenter) Hasher(com.google.common.hash.Hasher) HashCode(com.google.common.hash.HashCode) CoordinatorRegistryCenter(com.paascloud.core.registry.base.CoordinatorRegistryCenter)

Example 32 with Hasher

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

the class DefaultFileHasher method hash.

@Override
public HashCode hash(TextResource resource) {
    Hasher hasher = createFileHasher();
    hasher.putString(resource.getText(), Charsets.UTF_8);
    return hasher.hash();
}
Also used : Hasher(com.google.common.hash.Hasher)

Example 33 with Hasher

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

the class DefaultFileHasher method createFileHasher.

private static Hasher createFileHasher() {
    Hasher hasher = Hashing.md5().newHasher();
    hasher.putBytes(SIGNATURE);
    return hasher;
}
Also used : Hasher(com.google.common.hash.Hasher)

Example 34 with Hasher

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

the class DefaultFileHasher method doHash.

private HashCode doHash(InputStream inputStream) throws IOException {
    try {
        byte[] buffer = takeBuffer();
        try {
            Hasher hasher = createFileHasher();
            while (true) {
                int nread = inputStream.read(buffer);
                if (nread < 0) {
                    break;
                }
                hasher.putBytes(buffer, 0, nread);
            }
            return hasher.hash();
        } finally {
            returnBuffer(buffer);
        }
    } finally {
        inputStream.close();
    }
}
Also used : Hasher(com.google.common.hash.Hasher)

Example 35 with Hasher

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

the class DefaultClasspathEntryHasher method hash.

@Override
public HashCode hash(FileDetails fileDetails) {
    if (fileDetails.getType() == FileType.Directory || fileDetails.getType() == FileType.Missing) {
        return null;
    }
    String name = fileDetails.getName();
    final Hasher hasher = createHasher();
    if (FileUtils.isJar(name)) {
        return hashJar(fileDetails, hasher, classpathContentHasher);
    } else {
        return hashFile(fileDetails, hasher, classpathContentHasher);
    }
}
Also used : Hasher(com.google.common.hash.Hasher)

Aggregations

Hasher (com.google.common.hash.Hasher)59 IOException (java.io.IOException)10 HashCode (com.google.common.hash.HashCode)9 Test (org.junit.Test)9 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