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

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

Introduction

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

Prototype

public static HashFunction md5() 

Source Link

Document

Returns a hash function implementing the MD5 hash algorithm (128 hash bits) by delegating to the MD5 MessageDigest .

Usage

From source file:sockslib.common.Socks5UserPrincipal.java

@Override
public int hashCode() {
    return Hashing.md5().newHasher().putString(username, Charsets.UTF_8).hashCode();
}

From source file:org.onosproject.store.primitives.impl.DatabasePartitioner.java

protected int hash(String key) {
    return Math.abs(Hashing.md5().newHasher().putBytes(key.getBytes(Charsets.UTF_8)).hash().asInt());
}

From source file:net.portalblockz.portalbot.webinterface.WebIntHandler.java

public WebIntHandler() throws Exception {
    customFile = false;//  w  w w .ja  v  a2  s  .  c o  m
    indexFile = new File("index.html");
    HashCode hash = Files.hash(indexFile, Hashing.md5());
    indexHash = hash.toString();
    if (!indexFile.exists()) {
        StringBuilder reply = new StringBuilder();
        reply.append("<html><head><title>portalBot</title></head><body>");
        reply.append("<h1 style=\"color:red\">portalBot IRC Bot</h1>");
        reply.append(
                "<p>This is the default page for portalBot IRC Bot web interface... please add a page by adding index.html to your bot's root folder!</p>");
        reply.append("<br><p> %servers% </p>");
        reply.append("</body></html>");
        defaultContent = reply.toString();
    } else {
        customFile = true;
        reply = readFile(indexFile);
    }
    year = new SimpleDateFormat("yyyy").format(new Date());
}

From source file:io.github.maxymania.powercache.memcached.MemCachingApplier.java

/**
 * //  w  w w .  ja v a 2  s  . co m
 * @param client Memcached Connection
 * @param expires Expiration time in MS
 */
public MemCachingApplier(MemcachedClient client, int expires) {
    hf = Hashing.md5();
    this.client = client;
    this.expires = expires;
}

From source file:org.swiftexplorer.util.FileUtils.java

public static String readAllAndgetMD5(InputStream in) throws IOException {
    com.google.common.hash.HashingInputStream his = null;
    try {/*  w ww  .  j a  v  a2 s  .  co  m*/
        his = new com.google.common.hash.HashingInputStream(Hashing.md5(), in);

        final int bufferSize = 2097152;
        final ReadableByteChannel inputChannel = Channels.newChannel(his);
        final ByteBuffer buffer = ByteBuffer.allocateDirect(bufferSize);
        while (inputChannel.read(buffer) != -1) {
            buffer.clear();
        }
        /*
        byte[] bytesBuffer = new byte[bufferSize] ;
        int r = his.read(bytesBuffer, 0, bufferSize) ;
        while (r != -1)
           r = his.read(bytesBuffer) ;
        */
        HashCode hc = his.hash();
        return (hc != null) ? (hc.toString()) : (null);
    } finally {
        if (his != null)
            his.close();
    }
}

From source file:org.jmingo.util.FileUtils.java

public static String checksum(File file) {
    String checksum;//from  w  w  w . j  a  v  a2s. c  om
    try {
        checksum = com.google.common.io.Files.hash(file, Hashing.md5()).toString();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    return checksum;
}

From source file:lumbermill.Fingerprint.java

/**
 * Creates an MD5 hash based on raw event, this is stored under metadata field name 'fingerprint' (using same name as logstash).
 *
 * <pre>//from w  ww  .j  av  a 2  s.c  o  m
 *
 * Groovy usage that creates a hash from two fields:
 *  {@code
 * fingerprint.md5()
 * }
 * </pre>
 */
public static <E extends Event> Func1<E, Observable<E>> md5() {

    return e -> {
        String hashOfContents = Hashing.md5().hashString(e.raw().utf8(), Charsets.UTF_8).toString();
        // as Metadata
        return e.put("fingerprint", hashOfContents).toObservable();
    };
}

From source file:org.anarres.qemu.examples.AbstractQEmuExample.java

@Nonnull
private File download(@Nonnull URI source) throws IOException {
    File dir = new File("build/images/downloaded");
    HashCode hash = Hashing.md5().hashString(source.toString(), Charsets.UTF_8);
    File file = new File(dir, hash.toString());
    if (!file.exists()) {
        InputStream in = source.toURL().openStream();
        try {/* w ww .  j a  v  a2  s  .com*/
            Files.asByteSink(file).writeFrom(in);
        } finally {
            Closeables.close(in, false);
        }
    }
    return file;
}

From source file:net.yoomai.wechat.utils.StringUtils.java

/**
 * ????/*from w  w  w.  j a v  a  2  s  . c  om*/
 *
 * @param params  ?ASCII ????
 * @param encrypt ? SHA1 MD5
 * @return
 */
public static String signature(String buffer, String encrypt, boolean toUpperCase) {
    String sign = "";

    if ("MD5".equals(encrypt)) {
        // MD5
        sign = Hashing.md5().hashString(buffer, Charsets.UTF_8).toString();
    } else if ("SHA1".equals(encrypt)) {
        // SHA1
        sign = Hashing.sha1().hashString(buffer, Charsets.UTF_8).toString();
    }

    if (toUpperCase) {
        sign = sign.toUpperCase();
    }

    return sign;
}

From source file:org.gradle.internal.classloader.DefaultHashingClassLoaderFactory.java

private static HashCode calculateFilterSpecHash(FilteringClassLoader.Spec spec) {
    Hasher hasher = Hashing.md5().newHasher();
    addToHash(hasher, spec.getClassNames());
    addToHash(hasher, spec.getPackageNames());
    addToHash(hasher, spec.getPackagePrefixes());
    addToHash(hasher, spec.getResourcePrefixes());
    addToHash(hasher, spec.getResourceNames());
    addToHash(hasher, spec.getDisallowedClassNames());
    addToHash(hasher, spec.getDisallowedPackagePrefixes());
    return hasher.hash();
}