本文整理匯總了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);
}