本文整理汇总了Java中com.google.common.hash.Hashing.md5方法的典型用法代码示例。如果您正苦于以下问题:Java Hashing.md5方法的具体用法?Java Hashing.md5怎么用?Java Hashing.md5使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.hash.Hashing
的用法示例。
在下文中一共展示了Hashing.md5方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.google.common.hash.Hashing; //导入方法依赖的package包/类
public CacheEntry build() {
Path baseDir = cacheDir.resolve(name);
if (!keys.isEmpty()) {
HashFunction hf = Hashing.md5();
Hasher h = hf.newHasher();
for (String key : keys) {
h.putString(key, Charsets.UTF_8);
}
HashCode hc = h.hash();
baseDir = baseDir.resolve(hc.toString());
}
cacheEntriesLock.lock();
try {
CacheEntry cacheEntry = cacheEntries.get(baseDir.toString());
if (cacheEntry != null) {
if (!cacheEntry.getKeys().equals(keys)) {
throw new PowsyblException("Inconsistent hash");
}
} else {
cacheEntry = new CacheEntry(baseDir, keys);
cacheEntries.put(baseDir.toString(), cacheEntry);
}
return cacheEntry;
} finally {
cacheEntriesLock.unlock();
}
}
示例2: getHardwareProperties
import com.google.common.hash.Hashing; //导入方法依赖的package包/类
/**
* Returns the hardware properties defined in
* {@link AvdManager#HARDWARE_INI} as a {@link Map}.
*
* This is intended to be dumped in the config.ini and already contains
* the device name, manufacturer and device hash.
*
* @param d The {@link Device} from which to derive the hardware properties.
* @return A {@link Map} of hardware properties.
*/
@NonNull
public static Map<String, String> getHardwareProperties(@NonNull Device d) {
Map<String, String> props = getHardwareProperties(d.getDefaultState());
for (State s : d.getAllStates()) {
if (s.getKeyState().equals(KeyboardState.HIDDEN)) {
props.put("hw.keyboard.lid", getBooleanVal(true));
}
}
HashFunction md5 = Hashing.md5();
Hasher hasher = md5.newHasher();
ArrayList<String> keys = new ArrayList<String>(props.keySet());
Collections.sort(keys);
for (String key : keys) {
if (key != null) {
hasher.putString(key, Charsets.UTF_8);
String value = props.get(key);
hasher.putString(value == null ? "null" : value, Charsets.UTF_8);
}
}
// store the hash method for potential future compatibility
String hash = "MD5:" + hasher.hash().toString();
props.put(AvdManager.AVD_INI_DEVICE_HASH_V2, hash);
props.remove(AvdManager.AVD_INI_DEVICE_HASH_V1);
props.put(AvdManager.AVD_INI_DEVICE_NAME, d.getId());
props.put(AvdManager.AVD_INI_DEVICE_MANUFACTURER, d.getManufacturer());
return props;
}
示例3: getHashFor
import com.google.common.hash.Hashing; //导入方法依赖的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";
}
}
示例4: forName
import com.google.common.hash.Hashing; //导入方法依赖的package包/类
public static HashFunction forName(String name) {
switch (name) {
case "murmur3_32":
return Hashing.murmur3_32();
case "murmur3_128":
return Hashing.murmur3_128();
case "crc32":
return Hashing.crc32();
case "md5":
return Hashing.md5();
default:
throw new IllegalArgumentException("Can't find hash function with name " + name);
}
}
示例5: forName
import com.google.common.hash.Hashing; //导入方法依赖的package包/类
/** Return the hash function corresponding to a given message-digest algorithm given by name.
*
* @param messageDigest a message-digest algorithm (e.g., <code>MurmurHash3</code> or <code>MD5</code>); {@code null} if {@code messageDigest} is the empty string.
*/
@SuppressWarnings("deprecation")
public final static HashFunction forName(final String messageDigest) throws NoSuchAlgorithmException {
if ("".equals(messageDigest)) return null;
if ("MD5".equalsIgnoreCase(messageDigest)) return Hashing.md5();
if ("MurmurHash3".equalsIgnoreCase(messageDigest)) return Hashing.murmur3_128();
throw new NoSuchAlgorithmException("Unknown hash function " + messageDigest);
}
示例6: createCacheKeyBuilder
import com.google.common.hash.Hashing; //导入方法依赖的package包/类
protected CacheKeyBuilder createCacheKeyBuilder(FileHasher fileHasher, ClassPathSnapshotter snapshotter, ClassLoaderHierarchyHasher classLoaderHierarchyHasher) {
return new DefaultCacheKeyBuilder(Hashing.md5(), fileHasher, snapshotter, classLoaderHierarchyHasher);
}