Example usage for com.google.common.hash HashCode toString

List of usage examples for com.google.common.hash HashCode toString

Introduction

In this page you can find the example usage for com.google.common.hash HashCode toString.

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string containing each byte of #asBytes , in order, as a two-digit unsigned hexadecimal number in lower case.

Usage

From source file:com.codenvy.dto.generator.DtoGenerator.java

private static String getApiHash(String packageName) throws IOException {
    byte[] fileBytes = packageName.getBytes();
    HashCode hashCode = Hashing.sha1().hashBytes(fileBytes);
    return hashCode.toString();
}

From source file:com.facebook.buck.rules.Sha1HashCode.java

public static Sha1HashCode newRandomHashCode() {
    HashCode randomHashCode = Hashing.sha1().newHasher().putString(UUID.randomUUID().toString(), Charsets.UTF_8)
            .hash();/*w  ww .j av a  2s  . c o m*/
    return new Sha1HashCode(randomHashCode.toString());
}

From source file:EntityAndQueries.Queries.java

private static String Hashing(String password) {
    HashFunction function = Hashing.sha256();
    HashCode code = (HashCode) function.newHasher().putString(password, Charsets.UTF_8).hash();
    String passWord1 = code.toString();
    return passWord1;
}

From source file:io.scigraph.owlapi.OwlApiUtils.java

static String hash(String input) {
    // TODO: This may negatively impact performance but will reduce hash collisions. #150
    HashCode code = HASHER.newHasher().putString(input, Charsets.UTF_8).hash();
    return code.toString();
}

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//from w ww. j a  va  2  s .co 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:org.jclouds.glacier.util.AWSRequestSignerV4.java

private static String createStringToSign(String date, String credentialScope, HashCode hashedCanonicalRequest) {
    return ALGORITHM + "\n" + date + "\n" + credentialScope + "\n" + hashedCanonicalRequest.toString();
}

From source file:com.android.builder.internal.incremental.FileEntity.java

/**
 * Computes the sha1 of a file and returns it.
 *
 * @param f the file to compute the sha1 for.
 * @return the sha1 value/*w ww .java 2  s .  com*/
 * @throws Sha1Exception if the sha1 value cannot be computed.
 */
static String getSha1(File f) throws Sha1Exception {
    synchronized (sBuffer) {

        try {
            HashCode value = ByteStreams.hash(Files.newInputStreamSupplier(f), Hashing.sha1());
            return value.toString();
        } catch (Exception e) {
            throw new Sha1Exception(f, e);
        }
    }
}

From source file:org.sonatype.nexus.repository.maven.internal.hosted.metadata.MetadataUtils.java

/**
 * Writes passed in metadata as XML.//  w ww .  ja  v  a  2  s .c  o  m
 */
public static void write(final Repository repository, final MavenPath mavenPath, final Metadata metadata)
        throws IOException {
    MavenFacet mavenFacet = repository.facet(MavenFacet.class);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    MavenModels.writeMetadata(buffer, metadata);
    mavenFacet.put(mavenPath, new BytesPayload(buffer.toByteArray(), MavenMimeRulesSource.METADATA_TYPE));
    final Map<HashAlgorithm, HashCode> hashCodes = mavenFacet.get(mavenPath).getAttributes()
            .require(Content.CONTENT_HASH_CODES_MAP, Content.T_CONTENT_HASH_CODES_MAP);
    checkState(hashCodes != null, "hashCodes");
    for (HashType hashType : HashType.values()) {
        MavenPath checksumPath = mavenPath.hash(hashType);
        HashCode hashCode = hashCodes.get(hashType.getHashAlgorithm());
        checkState(hashCode != null, "hashCode: type=%s", hashType);
        mavenFacet.put(checksumPath, new StringPayload(hashCode.toString(), Constants.CHECKSUM_CONTENT_TYPE));
    }
}

From source file:storage.ConfigSaver.java

/**
 * Calculates a MD5 hash String for a ModuleConfiguration.
 * //from   ww w  .  java2s  .  co m
 * @param config
 * @return MD5 hash String
 */
public static String hash(ModuleConfiguration config) {
    try {
        if (config != null) {
            ByteArrayOutputStream byteArray = new ByteArrayOutputStream(1200);
            initMapper().writeValue(byteArray, config);
            HashFunction hashFunction = Hashing.md5();
            HashCode hashCode = hashFunction.newHasher().putBytes(byteArray.toByteArray()).hash();
            return hashCode.toString();
        }
    } catch (IOException e) {
        EXCEPTION_LOGGER.log(Level.SEVERE, "Exception at hash()", e);
    }
    return "";
}

From source file:net.jamcraft.chowtime.remote.RemoteMain.java

public static void HashCTD() {
    try {/*  w w w  .  j a  va  2 s.co  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();
    }
}