本文整理汇总了Java中com.google.common.hash.HashFunction.hashString方法的典型用法代码示例。如果您正苦于以下问题:Java HashFunction.hashString方法的具体用法?Java HashFunction.hashString怎么用?Java HashFunction.hashString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.hash.HashFunction
的用法示例。
在下文中一共展示了HashFunction.hashString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJarFilePrefix
import com.google.common.hash.HashFunction; //导入方法依赖的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();
}
示例2: getDirectoryNameForJar
import com.google.common.hash.HashFunction; //导入方法依赖的package包/类
/**
* Chooses a directory name, based on a JAR file name, considering exploded-aar and classes.jar.
*/
public static String getDirectoryNameForJar(File inputFile) {
// add a hash of the original file path.
HashFunction hashFunction = Hashing.sha1();
HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charsets.UTF_16LE);
String name = Files.getNameWithoutExtension(inputFile.getName());
if (name.equals("classes") && inputFile.getAbsolutePath().contains("exploded-aar")) {
// This naming scheme is coming from DependencyManager#computeArtifactPath.
File versionDir = inputFile.getParentFile().getParentFile();
File artifactDir = versionDir.getParentFile();
File groupDir = artifactDir.getParentFile();
name = Joiner.on('-').join(
groupDir.getName(), artifactDir.getName(), versionDir.getName());
}
name = name + "_" + hashCode.toString();
return name;
}
示例3: getJackFileName
import com.google.common.hash.HashFunction; //导入方法依赖的package包/类
/**
* Returns a unique File for the converted library, even if there are 2 libraries with the same
* file names (but different paths)
*
* @param outFolder the output folder.
* @param inputFile the library
*/
@NonNull
public static File getJackFileName(@NonNull File outFolder, @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 new File(outFolder, name + "-" + hashCode.toString() + SdkConstants.DOT_JAR);
}
示例4: getDirectoryNameForJar
import com.google.common.hash.HashFunction; //导入方法依赖的package包/类
/**
* Chooses a directory name, based on a JAR file name, considering exploded-aar and classes.jar.
*/
@NonNull
public static String getDirectoryNameForJar(@NonNull File inputFile) {
// add a hash of the original file path.
HashFunction hashFunction = Hashing.sha1();
HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charsets.UTF_16LE);
String name = Files.getNameWithoutExtension(inputFile.getName());
if (name.equals("classes") && inputFile.getAbsolutePath().contains("exploded-aar")) {
// This naming scheme is coming from DependencyManager#computeArtifactPath.
File versionDir = inputFile.getParentFile().getParentFile();
File artifactDir = versionDir.getParentFile();
File groupDir = artifactDir.getParentFile();
name = Joiner.on('-').join(
groupDir.getName(), artifactDir.getName(), versionDir.getName());
}
name = name + "_" + hashCode.toString();
return name;
}
示例5: getDexFileName
import com.google.common.hash.HashFunction; //导入方法依赖的package包/类
private String getDexFileName(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
HashFunction hashFunction = Hashing.md5();
HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charsets.UTF_16LE);
return name + "-" + hashCode.toString() + ".jar";
}
示例6: password
import com.google.common.hash.HashFunction; //导入方法依赖的package包/类
public static HashCode password(final String username) {
HashFunction _md5 = Hashing.md5();
return _md5.hashString(username);
}
示例7: testMd5
import com.google.common.hash.HashFunction; //导入方法依赖的package包/类
@Test
public void testMd5() {
HashFunction md5 = Hashing.md5();
HashCode hashString = md5.hashString("BeforeHash", Charset.defaultCharset());
assertEquals("86b3a7bd44852cf9cc897e262ccb4edd", hashString.toString());
}
示例8: testSha512
import com.google.common.hash.HashFunction; //导入方法依赖的package包/类
@Test
public void testSha512() {
HashFunction sha512 = Hashing.sha512();
HashCode hashString = sha512.hashString("BeforeHash", Charset.defaultCharset());
assertEquals("12ccc1ec7265c18840ab0b5b70b8b776fca4015f3ed62eb0d2c2bf727fe8e108b77e9f49458e47e98d852861b8a0bb83a9b5dd4fe84f89ce3d5fe6623142426f", hashString.toString());
}
示例9: getIPHash
import com.google.common.hash.HashFunction; //导入方法依赖的package包/类
public static String getIPHash() {
// IP address is mixed with the users home directory,
// so that it can't be decrypted by the server.
String text = DataSources.EXTERNAL_IP + System.getProperty("user.home");
HashFunction hf = Hashing.md5();
HashCode hc = hf.hashString(text, Charsets.UTF_8);
String ipHash = hc.toString();
return ipHash;
}
示例10: HashGraph
import com.google.common.hash.HashFunction; //导入方法依赖的package包/类
/**
* Create a blank HashGraph
* @param hf The hashing function to be used
*/
public HashGraph(HashFunction hf){
this(hf, new ArrayList<Node[]>(), new HashMap<Node,HashCode>(), hf.hashString("", Charsets.UTF_8), new HashMap<Node,HashCode>());
}
示例11: newHash
import com.google.common.hash.HashFunction; //导入方法依赖的package包/类
/**
* Creates a UTF-8 encoded hash using the hash function
*
* @param input string to encode
* @param function hash function to use
* @return the hash code
*/
public static HashCode newHash(String input, HashFunction function) {
return function.hashString(input, Charsets.UTF_8);
}