本文整理匯總了Java中com.google.common.hash.HashCode類的典型用法代碼示例。如果您正苦於以下問題:Java HashCode類的具體用法?Java HashCode怎麽用?Java HashCode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HashCode類屬於com.google.common.hash包,在下文中一共展示了HashCode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: downloadUsingCacheFailsWhenTheHashIsIncorrect
import com.google.common.hash.HashCode; //導入依賴的package包/類
@Test
public void downloadUsingCacheFailsWhenTheHashIsIncorrect() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
final RemoteFile remoteFile = RemoteFile.of(
new URI("https://raw.githubusercontent.com/njlr/test-lib-a/3af013452fe6b448b1cb33bb81bb19da690ec764/BUCK"),
HashCode.fromString("aaaaaaaaaaaaaa4f244296b0fba7a70166dea49c9e8d3eacda58d67a"));
final Path cachePath = CacheTasks.getCachePath(fs, remoteFile);
final SettableFuture<Throwable> futureException = SettableFuture.create();
CacheTasks.downloadToCache(fs, remoteFile).subscribe(
next -> {},
error -> {
futureException.set(error);
},
() -> {});
final Throwable exception = futureException.get(5000L, TimeUnit.MILLISECONDS);
assertTrue(exception instanceof DownloadFileException);
assertTrue(exception.getCause() instanceof HashMismatchException);
}
示例2: affectedSince
import com.google.common.hash.HashCode; //導入依賴的package包/類
private DependentsSet affectedSince(JarSnapshot other) {
final Set<String> affected = new HashSet<String>();
for (Map.Entry<String, HashCode> otherClass : other.getHashes().entrySet()) {
String otherClassName = otherClass.getKey();
HashCode otherClassBytes = otherClass.getValue();
HashCode thisClsBytes = getHashes().get(otherClassName);
if (thisClsBytes == null || !thisClsBytes.equals(otherClassBytes)) {
//removed since or changed since
affected.add(otherClassName);
DependentsSet dependents = other.getAnalysis().getRelevantDependents(otherClassName);
if (dependents.isDependencyToAll()) {
return dependents;
}
affected.addAll(dependents.getDependentClasses());
}
}
return new DefaultDependentsSet(affected);
}
示例3: createSnapshot
import com.google.common.hash.HashCode; //導入依賴的package包/類
JarClasspathSnapshot createSnapshot(Iterable<JarArchive> jarArchives) {
Map<File, JarSnapshot> jarSnapshots = Maps.newHashMap();
Map<File, HashCode> jarHashes = Maps.newHashMap();
Set<String> allClasses = Sets.newHashSet();
Set<String> duplicateClasses = Sets.newHashSet();
for (JarArchive jar : jarArchives) {
JarSnapshot snapshot = jarSnapshotter.createSnapshot(jar);
jarSnapshots.put(jar.file, snapshot);
jarHashes.put(jar.file, snapshot.getHash());
for (String c : snapshot.getClasses()) {
if (!allClasses.add(c)) {
duplicateClasses.add(c);
}
}
}
JarClasspathSnapshotData jarClasspathSnapshotData = new JarClasspathSnapshotData(jarHashes, duplicateClasses);
return new JarClasspathSnapshot(jarSnapshots, jarClasspathSnapshotData);
}
示例4: checksumEquals
import com.google.common.hash.HashCode; //導入依賴的package包/類
public static boolean checksumEquals(File file, String checksum) {
if (file == null || !file.exists()) {
return false;
}
try {
HashCode hash = Files.hash(file, Hashing.sha1());
StringBuilder builder = new StringBuilder();
for (Byte hashBytes : hash.asBytes()) {
builder.append(Integer.toString((hashBytes & 0xFF) + 0x100, 16).substring(1));
}
return builder.toString().equals(checksum);
} catch (IOException e) {
OneClientLogging.error(e);
}
return false;
}
示例5: deserialize
import com.google.common.hash.HashCode; //導入依賴的package包/類
@Override
public RemoteFile deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext context) throws JsonParseException {
Preconditions.checkNotNull(jsonElement);
Preconditions.checkNotNull(type);
Preconditions.checkNotNull(context);
final JsonObject jsonObject = jsonElement.getAsJsonObject();
if (!jsonObject.has("url")) {
throw new JsonParseException("RemoteFile must have a URL. ");
}
final URI url = context.deserialize(jsonObject.get("url"), URI.class);
if (!jsonObject.has("sha256")) {
throw new JsonParseException("RemoteFile must have a sha256. ");
}
final HashCode sha256 = context.deserialize(jsonObject.get("sha256"), HashCode.class);
return RemoteFile.of(url, sha256);
}
示例6: TaskTypeTaskStateChanges
import com.google.common.hash.HashCode; //導入依賴的package包/類
public TaskTypeTaskStateChanges(TaskExecution previousExecution, TaskExecution currentExecution, String taskPath, Class<? extends TaskInternal> taskClass, Collection<ClassLoader> taskActionClassLoaders, ClassLoaderHierarchyHasher classLoaderHierarchyHasher) {
String taskClassName = taskClass.getName();
currentExecution.setTaskClass(taskClassName);
HashCode taskClassLoaderHash = classLoaderHierarchyHasher.getClassLoaderHash(taskClass.getClassLoader());
currentExecution.setTaskClassLoaderHash(taskClassLoaderHash);
HashCode taskActionsClassLoaderHash = calculateActionClassLoaderHash(taskActionClassLoaders, classLoaderHierarchyHasher);
currentExecution.setTaskActionsClassLoaderHash(taskActionsClassLoaderHash);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Task {} class loader hash: {}", taskPath, taskClassLoaderHash);
LOGGER.info("Task {} actions class loader hash: {}", taskPath, taskActionsClassLoaderHash);
}
this.taskPath = taskPath;
this.taskClass = taskClassName;
this.taskClassLoaderHash = taskClassLoaderHash;
this.taskActionsClassLoaderHash = taskActionsClassLoaderHash;
this.previousExecution = previousExecution;
}
示例7: get
import com.google.common.hash.HashCode; //導入依賴的package包/類
@Override
public ClassLoader get(ClassLoaderId id, ClassPath classPath, @Nullable ClassLoader parent, @Nullable FilteringClassLoader.Spec filterSpec, HashCode overrideHashCode) {
ClassPathSnapshot classPathSnapshot = snapshotter.snapshot(classPath);
ClassLoaderSpec spec = new ClassLoaderSpec(parent, classPathSnapshot, filterSpec, overrideHashCode);
synchronized (lock) {
CachedClassLoader cachedLoader = byId.get(id);
if (cachedLoader == null || !cachedLoader.is(spec)) {
CachedClassLoader newLoader = getAndRetainLoader(classPath, spec, id);
byId.put(id, newLoader);
if (cachedLoader != null) {
LOGGER.debug("Releasing previous classloader for {}", id);
cachedLoader.release(id);
}
return newLoader.classLoader;
} else {
return cachedLoader.classLoader;
}
}
}
示例8: deserialize
import com.google.common.hash.HashCode; //導入依賴的package包/類
@Override
public RemoteArchive deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext context) throws JsonParseException {
Preconditions.checkNotNull(jsonElement);
Preconditions.checkNotNull(type);
Preconditions.checkNotNull(context);
final JsonObject jsonObject = jsonElement.getAsJsonObject();
if (!jsonObject.has("url")) {
throw new JsonParseException("A remote archive must have a URL");
}
final URI url = context.deserialize(jsonObject.get("url"), URI.class);
final HashCode sha256 = context.deserialize(jsonObject.get("sha256"), HashCode.class);
final Optional<String> subPath = jsonObject.has("subPath") ?
Optional.of(jsonObject.get("subPath").getAsString()) :
Optional.empty();
return RemoteArchive.of(url, sha256, subPath);
}
示例9: downloadRemoteFileCompletes
import com.google.common.hash.HashCode; //導入依賴的package包/類
@Test
public void downloadRemoteFileCompletes() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
final RemoteFile remoteFile = RemoteFile.of(
new URI("https://raw.githubusercontent.com/nikhedonia/googletest/665327f0141d4a4fc4f2496e781dce436d742645/BUCK"),
HashCode.fromString("d976069f5b47fd8fc57201f47026a70dee4e47b3141ac23567b8a0c56bf9288c"));
final SettableFuture<Boolean> future = SettableFuture.create();
CommonTasks.downloadRemoteFile(fs, remoteFile, fs.getPath("test.txt").toAbsolutePath())
.subscribe(
next -> {
},
error -> {
future.set(false);
},
() -> {
future.set(true);
});
assertTrue(future.get(30, TimeUnit.SECONDS));
}
示例10: getCacheKey
import com.google.common.hash.HashCode; //導入依賴的package包/類
public String getCacheKey() {
Hasher hasher = hf.newHasher();
hasher.putUnencodedChars(queryKey);
for (Number id : ids) {
if (id instanceof Integer) {
hasher.putInt(id.intValue());
} else if (id instanceof Long) {
hasher.putLong(id.longValue());
} else if (id instanceof Short) {
hasher.putLong(id.shortValue());
} else if (id instanceof Double) {
hasher.putDouble(id.doubleValue());
} else if (id instanceof Float) {
hasher.putFloat(id.floatValue());
} else if (id instanceof Byte) {
hasher.putFloat(id.byteValue());
}
}
HashCode hashcode = hasher.hash();
return hashcode.toString();
}
示例11: updateState
import com.google.common.hash.HashCode; //導入依賴的package包/類
public boolean updateState()
throws IOException
{
// only check contents if length or modified time changed
long newLastModified = file.lastModified();
long newLength = file.length();
if (lastModified == newLastModified && length == newLength) {
return false;
}
// update stats
lastModified = newLastModified;
length = newLength;
// check if contents changed
HashCode newHashCode = Files.hash(file, sha256());
if (Objects.equals(hashCode, newHashCode)) {
return false;
}
hashCode = newHashCode;
return true;
}
示例12: getAllEligibleJobContexts
import com.google.common.hash.HashCode; //導入依賴的package包/類
/**
* 從失效轉移隊列中獲取所有有資格執行的作業上下文.
*
* @return 有資格執行的作業上下文集合
*/
public Collection<JobContext> getAllEligibleJobContexts() {
if (!regCenter.isExisted(FailoverNode.ROOT)) {
return Collections.emptyList();
}
List<String> jobNames = regCenter.getChildrenKeys(FailoverNode.ROOT);
Collection<JobContext> result = new ArrayList<>(jobNames.size());
Set<HashCode> assignedTasks = new HashSet<>(jobNames.size() * 10, 1);
for (String each : jobNames) {
List<String> taskIdList = regCenter.getChildrenKeys(FailoverNode.getFailoverJobNodePath(each));
if (taskIdList.isEmpty()) {
regCenter.remove(FailoverNode.getFailoverJobNodePath(each));
continue;
}
Optional<CloudJobConfiguration> jobConfig = configService.load(each);
if (!jobConfig.isPresent()) {
regCenter.remove(FailoverNode.getFailoverJobNodePath(each));
continue;
}
List<Integer> assignedShardingItems = getAssignedShardingItems(each, taskIdList, assignedTasks);
if (!assignedShardingItems.isEmpty() && jobConfig.isPresent()) {
result.add(new JobContext(jobConfig.get(), assignedShardingItems, ExecutionType.FAILOVER));
}
}
return result;
}
示例13: saveAsset
import com.google.common.hash.HashCode; //導入依賴的package包/類
/**
* Save an asset and create a blob
*
* @return blob content
*/
private static Content saveAsset(final StorageTx tx,
final Asset asset,
final Supplier<InputStream> contentSupplier,
final String contentType,
final AttributesMap contentAttributes,
final HashCode hash) throws IOException
{
Content.applyToAsset(asset, maintainLastModified(asset, contentAttributes));
AssetBlob assetBlob = tx.setBlob(
asset, asset.name(), contentSupplier, HASH_ALGORITHMS, null, contentType, false
);
if(!hashVerifier.verify(hash, assetBlob.getHashes().get(MD5))) {
return null;
}
asset.markAsDownloaded();
tx.saveAsset(asset);
return toContent(asset, assetBlob.getBlob());
}
示例14: getJarFilePrefix
import com.google.common.hash.HashCode; //導入依賴的package包/類
/**
* Files exported from jars are exported into a certain folder so that we can rebuild them
* when the related jar file changes.
*/
@NonNull
private static String getJarFilePrefix(@NonNull File inputFile) {
// get the filename
String name = inputFile.getName();
// remove the extension
int pos = name.lastIndexOf('.');
if (pos != -1) {
name = name.substring(0, pos);
}
// add a hash of the original file path.
String input = inputFile.getAbsolutePath();
HashFunction hashFunction = Hashing.sha1();
HashCode hashCode = hashFunction.hashString(input, Charsets.UTF_16LE);
return name + "-" + hashCode.toString();
}
示例15: getHashFor
import com.google.common.hash.HashCode; //導入依賴的package包/類
private String getHashFor(File inputFile) {
String retval = alreadyChecked.get(inputFile.getAbsolutePath());
if (retval != null) return retval;
// add a hash of the original file path
try {
HashFunction hashFunction = Hashing.md5();
HashCode hashCode = hashFunction.hashBytes(Files.readAllBytes(inputFile.toPath()));
retval = hashCode.toString();
alreadyChecked.put(inputFile.getAbsolutePath(), retval);
return retval;
} catch (IOException e) {
e.printStackTrace();
return "ERROR";
}
}