Example usage for com.google.common.hash Hashing sha1

List of usage examples for com.google.common.hash Hashing sha1

Introduction

In this page you can find the example usage for com.google.common.hash Hashing sha1.

Prototype

public static HashFunction sha1() 

Source Link

Document

Returns a hash function implementing the SHA-1 algorithm (160 hash bits) by delegating to the SHA-1 MessageDigest .

Usage

From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java

private static Path getDerivedSourcesDirectoryForBuildTarget(BuildTarget buildTarget, ProjectFilesystem fs) {
    String fullTargetName = buildTarget.getFullyQualifiedName();
    byte[] utf8Bytes = fullTargetName.getBytes(Charset.forName("UTF-8"));

    Hasher hasher = Hashing.sha1().newHasher();
    hasher.putBytes(utf8Bytes);/* www  . j  ava  2 s  . c  om*/

    String targetSha1Hash = hasher.hash().toString();
    String targetFolderName = buildTarget.getShortName() + "-" + targetSha1Hash;

    Path xcodeDir = fs.getBuckPaths().getXcodeDir();
    Path derivedSourcesDir = xcodeDir.resolve("derived-sources").resolve(targetFolderName);

    return derivedSourcesDir;
}

From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java

private Path getFilenameToHeadersPath(TargetNode<? extends CxxLibraryDescription.CommonArg> targetNode,
        String suffix) {/* ww  w  .ja  v  a2s .c o  m*/
    String hashedPath = BaseEncoding.base64Url().omitPadding()
            .encode(Hashing.sha1()
                    .hashString(targetNode.getBuildTarget().getUnflavoredBuildTarget().getFullyQualifiedName(),
                            Charsets.UTF_8)
                    .asBytes())
            .substring(0, 10);
    return Paths.get(hashedPath + suffix);
}