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:com.google.devtools.build.lib.analysis.ServerDirectories.java

private static HashCode checkMD5(HashCode hash) {
    Preconditions.checkArgument(hash.bits() == Hashing.md5().bits(), "Hash '%s' has %s bits", hash,
            hash.bits());/*from   w  ww .  j  av a 2s . c  o m*/
    return hash;
}

From source file:org.gradle.api.internal.hash.DefaultHasher.java

public HashCode hash(File file) {
    try {//from  w  w w  . ja  v  a  2 s .c om
        com.google.common.hash.Hasher hasher = Hashing.md5().newHasher();
        hasher.putBytes(SIGNATURE);
        Files.copy(file, Funnels.asOutputStream(hasher));
        return hasher.hash();
    } catch (IOException e) {
        throw new UncheckedIOException(String.format("Failed to create MD5 hash for file '%s'.", file), e);
    }
}

From source file:org.talos.CFGScanDroid.Match.java

public Match(File file, CFGSig signature, ControlFlowGraph cfg) {
    this.fileName = file.getPath();
    try {//w ww .  j  a  va  2s .  c om
        this.fileMD5 = Files.hash(file, Hashing.md5()).toString();
        this.fileSHA256 = Files.hash(file, Hashing.sha256()).toString();
    } catch (IOException e) {
        e.printStackTrace();
    }
    this.cfg = cfg;
    this.signature = signature;
}

From source file:com.google.api.control.aggregator.MetricValues.java

/**
 * Obtains the {@code HashCode} for the contents of {@code value}.
 *
 * @param value a {@code MetricValue} to be signed
 * @return the {@code HashCode} corresponding to {@code value}
 *///from   w w  w  . ja  v a2 s .  co m
public static HashCode sign(MetricValue value) {
    Hasher h = Hashing.md5().newHasher();
    return putMetricValue(h, value).hash();
}

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

public static String getMD5(File file) throws IOException {
    if (file.isDirectory())
        return emptyMd5;
    HashCode hc = com.google.common.io.Files.hash(file, Hashing.md5());
    return (hc != null) ? (hc.toString()) : (null);
}

From source file:de.jackwhite20.hftp.shared.file.FileData.java

public FileData(File file, boolean directory) {

    this.file = file;
    this.directory = directory;
    try {// w  w  w  . jav  a 2s.  co m
        this.hash = Files.hash(file, Hashing.md5()).toString();
    } catch (IOException ignore) {
        this.hash = "N/A";
    }
    this.size = Math.round((file.length() / MB) * 100F) / 100F;
}

From source file:com.bennavetta.appsite2.sync.Rsync.java

/**
 * Generate the list of blocks in the receiver's file that will be sent to the sender to run
 * the algorithm./*from   w  ww  .j a  v a 2 s  . c  o  m*/
 * @param input a stream to read blocks from
 * @param blockSize the block size to use. Must be the same on the client and server
 * @return a list containing the generated blocks
 * @throws IOException if there is an exception reading the data
 */
public static ObjectArrayList<Block> calculateBlocks(final InputStream input, final int blockSize)
        throws IOException {
    final ObjectArrayList<Block> blocks = new ObjectArrayList<Block>();
    final byte[] buf = new byte[blockSize];
    while (input.read(buf, 0, blockSize) != -1) {
        blocks.add(new Block(// NOPMD - point of method is to create Block objects in a loop
                RollingChecksum.checksum(buf, 0, blockSize), Hashing.md5().hashBytes(buf).asBytes()));
    }
    return blocks;
}

From source file:sockslib.common.AnonymousPrincipal.java

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

From source file:org.cinchapi.concourse.server.concurrent.Token.java

/**
 * Return a {@link Token} that wraps the specified {@code objects}.
 * /* w w  w. j av a  2 s . c om*/
 * @param objects
 * @return the Token
 */
public static Token wrap(Object... objects) {
    return new Token(ByteBuffer.wrap(Hashing.md5().hashUnencodedChars(Arrays.toString(objects)).asBytes()));
}

From source file:cn.exinhua.fetch.entity.Link.java

public Link(String anchor, String url) {
    this.anchor = anchor;
    this.url = url;
    this.hash = Hashing.md5().newHasher().putString(url, Charsets.UTF_8).hash().toString();
}