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;
}
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();
}
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;
}
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();
}
}
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);
}
}
Aggregations