List of usage examples for com.google.common.hash HashFunction hashString
HashCode hashString(CharSequence input, Charset charset);
From source file:com.qwazr.utils.HashUtils.java
public static final int getMurmur3Mod(final String hashString, Charset charset, final int mod) { HashFunction m3 = Hashing.murmur3_128(); if (charset == null) charset = Charset.defaultCharset(); return (Math.abs(m3.hashString(hashString, charset).asInt()) % mod); }
From source file:com.android.build.gradle.tasks.JackPreDexTransform.java
/** * Returns a unique file name for the converted library, even if there are 2 libraries with the * same file names (but different paths) * * @param inputFile the library/*ww w.j av a2s . c o m*/ */ @NonNull public static String getJackFileName(@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(); }
From source file:com.qubole.rubix.spi.CacheConfig.java
public static String getLocalDirFor(String remotePath, Configuration conf) { int numDisks = numDisks(conf); int numBuckets = 100 * numDisks; HashFunction hf = Hashing.murmur3_32(); HashCode hc = hf.hashString(remotePath, Charsets.UTF_8); int bucket = Math.abs(hc.asInt()) % numBuckets; int dirNum = (bucket / numDisks) % numDisks; String dirname = getDirPath(conf, dirNum) + CacheConfig.fileCacheDirSuffixConf; return dirname; }
From source file:com.android.build.gradle.tasks.PreDex.java
/** * Returns a unique File for the pre-dexed library, even * if there are 2 libraries with the same file names (but different * paths)// w ww . j av a 2 s. c o m * * If multidex is enabled the return File is actually a folder. * * @param outFolder the output folder. * @param inputFile the library. */ @NonNull static File getDexFileName(@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); }
From source file:com.android.build.gradle.tasks.JillTask.java
/** * Returns a unique File for the converted library, even if there are 2 libraries with the same * file names (but different paths)/*w w w .j a v a 2 s .c o m*/ * * @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); }
From source file:dodola.anole.lib.FileUtils.java
/** * Chooses a directory name, based on a JAR file name, considering exploded-aar and classes.jar. */// ww w .j a va 2 s . co m 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; }
From source file:com.android.utils.FileUtils.java
/** * Chooses a directory name, based on a JAR file name, considering exploded-aar and classes.jar. */// w ww . j a v a 2 s.c om @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; }
From source file:com.taobao.android.builder.tasks.app.databinding.AwbDataBindingMergeArtifactsTask.java
/** * Files exported from jars are exported into a certain folder so that we can rebuild them * when the related jar file changes./*from ww w . j a v a 2s. c om*/ */ @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(); }
From source file:net.jamcraft.chowtime.remote.RemoteMain.java
public static void HashCTD() { try {/*from ww w . j a va 2 s. c o m*/ HashFunction hasher = Hashing.md5(); FileReader fis = new FileReader(ModConstants.DYN_LOC + "/local.ctd"); BufferedReader br = new BufferedReader(fis); String line = br.readLine(); String file = ""; while (line != null) { file += line; line = br.readLine(); } HashCode hash = hasher.hashString(file, Charset.defaultCharset()); ChowTime.logger.info("Local.ctd hash digest(in hex format):: " + hash.toString()); localHash = hash.toString(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.android.build.gradle.internal.transforms.DexTransform.java
/** * Returns the hash of a file./* www . java 2 s .c o m*/ * * If the file is a folder, it's a hash of its path. If the file is a file, then * it's a hash of the file itself. * * @param file the file to hash */ @NonNull private static String getFileHash(@NonNull File file) throws IOException { HashCode hashCode; HashFunction hashFunction = Hashing.sha1(); if (file.isDirectory()) { hashCode = hashFunction.hashString(file.getPath(), Charsets.UTF_16LE); } else { hashCode = Files.hash(file, hashFunction); } return hashCode.toString(); }