List of usage examples for com.google.common.hash Hasher hash
@CheckReturnValue HashCode hash();
From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java
private HashCode getHeaderSymlinkTreeHashCode(ImmutableSortedMap<Path, Path> contents, Optional<String> moduleName, boolean shouldCreateHeadersSymlinks, boolean shouldCreateHeaderMap) { Hasher hasher = Hashing.sha1().newHasher(); hasher.putBytes(ruleKeyConfiguration.getCoreKey().getBytes(Charsets.UTF_8)); String symlinkState = shouldCreateHeadersSymlinks ? "symlinks-enabled" : "symlinks-disabled"; byte[] symlinkStateValue = symlinkState.getBytes(Charsets.UTF_8); hasher.putInt(symlinkStateValue.length); hasher.putBytes(symlinkStateValue);//from www.ja v a2s . c o m String hmapState = shouldCreateHeaderMap ? "hmap-enabled" : "hmap-disabled"; byte[] hmapStateValue = hmapState.getBytes(Charsets.UTF_8); hasher.putInt(hmapStateValue.length); hasher.putBytes(hmapStateValue); if (moduleName.isPresent()) { byte[] moduleNameValue = moduleName.get().getBytes(Charsets.UTF_8); hasher.putInt(moduleNameValue.length); hasher.putBytes(moduleNameValue); } hasher.putInt(0); for (Map.Entry<Path, Path> entry : contents.entrySet()) { byte[] key = entry.getKey().toString().getBytes(Charsets.UTF_8); byte[] value = entry.getValue().toString().getBytes(Charsets.UTF_8); hasher.putInt(key.length); hasher.putBytes(key); hasher.putInt(value.length); hasher.putBytes(value); } return hasher.hash(); }