Example usage for com.google.common.hash HashFunction newHasher

List of usage examples for com.google.common.hash HashFunction newHasher

Introduction

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

Prototype

Hasher newHasher(int expectedInputSize);

Source Link

Document

Begins a new hash code computation as #newHasher() , but provides a hint of the expected size of the input (in bytes).

Usage

From source file:com.tinspx.util.io.callbacks.HashingListener.java

public HashingListener(HashFunction hashFunction, int expectedInputSize) {
    this(hashFunction.newHasher(expectedInputSize));
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl.java

/**
 * compute pseudorandom key unique for given seed and {@link #auxiliaryId}
 * @param seed random int but fixed per session
 *///from   w  w  w . ja  v  a  2  s .c o m
public void init(int seed) {
    if (auxiliaryId <= 0) {
        throw new IllegalStateException("auxiliaryId must be greater than 0");
    }

    HashFunction mm32Hf = Hashing.murmur3_32(seed);
    Hasher hasher = mm32Hf.newHasher(8);
    hasher.putInt(auxiliaryId);
    long hash = 0xFFFFFFFFL & hasher.hash().asInt();
    cookie = (auxiliaryId << 24) | (hash >> 8);
}

From source file:com.github.nethad.clustermeister.api.Credentials.java

/**
 * Get a {@link Supplier} that returns the hex-string representation of the 
 * input's SHA-256 hash./*from www  .j  a v a2s  . co  m*/
 * 
 * The hash is only computed once and cached for further requests.
 * 
 * @param string the input.
 * @param charset   the charset of the input.
 * @return the hexadecimal string  representation of the {@code input}s hash code.
 */
protected Supplier<String> getSha256DigestSupplier(final String string, final Charset charset) {

    return Suppliers.memoize(new Supplier<String>() {

        @Override
        public String get() {
            if (string == null || string.isEmpty()) {
                return string;
            }
            HashFunction hf = Hashing.sha256();
            HashCode hc = hf.newHasher(string.length()).putString(string, charset).hash();
            return hc.toString();
        }
    });
}

From source file:org.fim.model.State.java

public String hashState() {
    HashFunction hashFunction = Hashing.sha512();
    Hasher hasher = hashFunction.newHasher(Constants._10_MB);
    hashObject(hasher);//from   ww  w  .j av a 2 s  .c  o  m
    HashCode hash = hasher.hash();
    return hash.toString();
}