Example usage for com.google.common.hash Hasher hash

List of usage examples for com.google.common.hash Hasher hash

Introduction

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

Prototype

@CheckReturnValue
HashCode hash();

Source Link

Document

Computes a hash code based on the data that have been provided to this hasher.

Usage

From source file:org.apache.openwhisk.example.maven.App.java

public static JsonObject main(JsonObject args) {
    JsonObject response = new JsonObject();
    if (args.has("text")) {
        String text = args.getAsJsonPrimitive("text").getAsString();
        try {//from   www.  j a  va2s  . c  om
            Hasher hasher = Hashing.md5().newHasher();
            hasher.putString(text.toString(), Charset.forName("UTF-8"));
            response.addProperty("text", text);
            response.addProperty("md5", hasher.hash().toString());
        } catch (Exception e) {
            response.addProperty("Error", e.getMessage());
        }
    }
    return response;
}

From source file:io.github.maxymania.powercache.hash.Util.java

public static byte[] hash(HashFunction hf, Object obj) {
    Hasher digest = hf.newHasher();
    digest.putObject(obj, funnel);//from   w w w . jav a 2 s .  co m
    return digest.hash().asBytes();
}

From source file:io.github.maxymania.powercache.hash.Util.java

public static byte[] hash(HashFunction hf, String catname, Object[] obj) {
    Hasher digest = hf.newHasher();
    digest.putString(catname, UTF);/*w  ww  .  ja  v a 2 s. c o m*/
    digest.putObject(obj, funnel);
    return digest.hash().asBytes();
}

From source file:org.liquigraph.model.Checksums.java

public static String checksum(Collection<String> queries) {
    Hasher hasher = Hashing.sha1().newHasher();
    for (String query : queries) {
        hasher = hasher.putString(query, Charsets.UTF_8);
    }//from  w  w  w . j a va 2 s .c  o  m
    return hasher.hash().toString();
}

From source file:com.github.luluvise.droid_utils.lib.HashUtils.java

/**
 * Gets a String hash generated using the passed hashing algorithm.
 *///from w  w  w  .  j a v a2 s  .co m
@Nonnull
public static String getHash(@Nonnull HashFunction hash, @Nonnull String... strings) {
    Hasher hasher = hash.newHasher();
    for (String input : strings) {
        hasher.putString(input);
    }
    return hasher.hash().toString();
}

From source file:epoxide.lpa.impl.StringUtil.java

public static String hash(HashFunction hf, Kryo kryo, Object obj) {
    Hasher ho = hf.newHasher();
    Output out = new Output(Funnels.asOutputStream(ho));
    kryo.writeClassAndObject(out, obj);//from  w w w  .  j av  a  2s .  c om
    out.close();
    return hex(ho.hash().asBytes());
}

From source file:com.github.marcosalis.kraken.utils.HashUtils.java

/**
 * Gets a String hash generated using the passed hashing algorithm.
 *///from  w  w w  .ja  va  2 s . c  om
@Nonnull
public static String getHash(@Nonnull HashFunction hash, @Nonnull String... strings) {
    final Hasher hasher = hash.newHasher();
    for (String input : strings) {
        hasher.putString(input);
    }
    return hasher.hash().toString();
}

From source file:org.sonatype.nexus.common.hash.Hashes.java

/**
 * Computes the hash of the given stream using the given function.
 *//*www  . ja  v  a 2  s. c  o m*/
public static HashCode hash(final HashFunction function, final InputStream input) throws IOException {
    Hasher hasher = function.newHasher();
    OutputStream output = Funnels.asOutputStream(hasher);
    ByteStreams.copy(input, output);
    return hasher.hash();
}

From source file:com.ibm.vicos.common.util.Utils.java

public static String hashMurmur3_32(String input) {
    Hasher hasher = Hashing.murmur3_32().newHasher();
    hasher.putString(input, Charsets.UTF_8);
    return hasher.hash().toString();
}

From source file:org.locationtech.geogig.plumbing.HashObject.java

public static ObjectId hashFeature(List<Object> values) {
    final Hasher hasher = ObjectId.HASH_FUNCTION.newHasher();

    HashObjectFunnels.feature(hasher, values);

    final byte[] rawKey = hasher.hash().asBytes();
    final ObjectId id = ObjectId.createNoClone(rawKey);

    return id;/*w w  w .j  a v  a 2s  .c om*/
}