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.medallia.tiny.string.JsString.java

/** @return a strong hash of the content of the given JsString objects */
public static String hash(JsString... jsStrings) {
    StringBuilder sb = new StringBuilder();
    for (JsString js : jsStrings)
        sb.append(js.getRawJs());/*from w  w  w .  j a  v  a  2 s  . c  o  m*/
    return Hashing.md5().hashString(sb.toString(), Charsets.UTF_8).toString();
}

From source file:cosmos.sql.impl.LogicVisitor.java

protected Iterable<MultimapRecord> apply(OrOperator andOp) {

    Iterable<MultimapRecord> iter = Collections.emptyList();
    Iterable<ChildVisitor> children = Iterables.filter(andOp.getChildren(), new FilterFilter());
    Iterator<ChildVisitor> childIter = children.iterator();

    while (childIter.hasNext()) {
        FieldEquality equality = (FieldEquality) childIter.next();

        iter = Iterables.concat(iter, apply(equality));

    }//from  w  ww  . j  ava 2  s.  c o  m

    Store meatadata = new Store(sortRes.connector(), sortRes.auths(), sortRes.columnsToIndex());

    try {
        cosmosRef.register(meatadata);
        cosmosRef.addResults(meatadata, iter);
        iter = Collections.emptyList();

        HashFunction hf = Hashing.md5();
        HashCode hc = hf.newHasher().putObject(andOp, andOp).hash();

        tempTableCache.put(hc.toString(), Maps.immutableEntry(cosmosRef, meatadata));

        return cosmosRef.fetch(meatadata);
    } catch (Exception e) {
        log.error("Could not fetch results", e);
    }

    return iter;
}

From source file:com.mac.holdempoker.app.impl.SimplePlayer.java

private void setPid(String... pidParts) {
    HashFunction hf = Hashing.md5();
    Hasher hasher = hf.newHasher();/*  www  . j a v a2 s.c  om*/
    for (String str : pidParts) {
        hasher.putString(str, Charset.forName("UTF-8"));
    }
    HashCode hc = hasher.hash();
    this.setPlayerId(hc.toString());
}

From source file:com.facebook.buck.versions.ParallelVersionedTargetGraphBuilder.java

/** @return a flavor to which summarizes the given version selections. */
static Flavor getVersionedFlavor(SortedMap<BuildTarget, Version> versions) {
    Preconditions.checkArgument(!versions.isEmpty());
    Hasher hasher = Hashing.md5().newHasher();
    for (Map.Entry<BuildTarget, Version> ent : versions.entrySet()) {
        hasher.putString(ent.getKey().toString(), Charsets.UTF_8);
        hasher.putString(ent.getValue().getName(), Charsets.UTF_8);
    }//from   w w w.  j a v a  2s  .  c  o  m
    return InternalFlavor.of("v" + hasher.hash().toString().substring(0, 7));
}

From source file:org.arbeitspferde.groningen.open.OpenModule.java

@Provides
@Singleton
public HashFunction getHashFunction() {
    return Hashing.md5();
}

From source file:com.google.cloud.storage.StorageImpl.java

@Override
public Blob create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options) {
    content = firstNonNull(content, EMPTY_BYTE_ARRAY);
    BlobInfo updatedInfo = blobInfo.toBuilder()
            .setMd5(BaseEncoding.base64().encode(Hashing.md5().hashBytes(content).asBytes()))
            .setCrc32c(//from w  ww .j ava2 s. c  om
                    BaseEncoding.base64().encode(Ints.toByteArray(Hashing.crc32c().hashBytes(content).asInt())))
            .build();
    return internalCreate(updatedInfo, content, options);
}

From source file:com.scireum.SDSMojo.java

private URL computeURL(String artifact, String contentHash) throws MalformedURLException {
    String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
    String input = identity + timestamp + key;
    String hash = Hashing.md5().newHasher().putString(input, Charsets.UTF_8).hash().toString();
    return new URL(
            "http://" + server + "/artifacts/" + artifact + "?contentHash=" + urlEncode(contentHash) + "&user="
                    + urlEncode(identity) + "&timestamp=" + urlEncode(timestamp) + "&hash=" + urlEncode(hash));
}

From source file:org.eclipse.che.api.vfs.impl.file.event.detectors.FileTrackingOperationReceiver.java

private String hashFile(String path) {
    try {// www .  j a  va 2 s.c om
        VirtualFile file = vfsProvider.getVirtualFileSystem().getRoot().getChild(Path.of(path));
        return Hashing.md5().hashString(file == null ? "" : file.getContentAsString(), defaultCharset())
                .toString();
    } catch (ServerException | ForbiddenException e) {
        LOG.error("Error trying to read {} file and broadcast it", path, e);
    }
    return null;
}

From source file:ninja.NinjaController.java

/**
 * Handles manual object uploads/*from ww  w .j  a v  a  2  s .c  o m*/
 *
 * @param ctx    the context describing the current request
 * @param bucket the name of the target bucket
 */
@Routed(priority = PriorityCollector.DEFAULT_PRIORITY - 1, value = "/ui/:1/upload")
public void uploadFile(WebContext ctx, String bucket) {
    try {
        String name = ctx.get("filename").asString(ctx.get("qqfile").asString());
        Bucket storageBucket = storage.getBucket(bucket);
        StoredObject object = storageBucket.getObject(name);
        try (InputStream inputStream = ctx.getContent()) {
            try (FileOutputStream out = new FileOutputStream(object.getFile())) {
                ByteStreams.copy(inputStream, out);
            }
        }

        Map<String, String> properties = Maps.newTreeMap();
        properties.put(HttpHeaderNames.CONTENT_TYPE.toString(),
                ctx.getHeaderValue(HttpHeaderNames.CONTENT_TYPE).asString(MimeHelper.guessMimeType(name)));
        HashCode hash = Files.hash(object.getFile(), Hashing.md5());
        String md5 = BaseEncoding.base64().encode(hash.asBytes());
        properties.put("Content-MD5", md5);
        object.storeProperties(properties);

        ctx.respondWith().direct(HttpResponseStatus.OK, "{ success: true }");
    } catch (IOException e) {
        UserContext.handle(e);
        ctx.respondWith().direct(HttpResponseStatus.OK, "{ success: false }");
    }
}

From source file:org.obiba.mica.study.service.StudyPackageImportServiceImpl.java

private void saveTempFile(Attachment attachment, ByteSource content) throws IOException {
    TempFile tempFile = new TempFile();
    tempFile.setId(attachment.getId());/*from w ww .ja  va2s  . c  o  m*/
    tempFile.setName(attachment.getName());
    tempFileService.addTempFile(tempFile, content.openStream());
    attachment.setMd5(content.hash(Hashing.md5()).toString());
    attachment.setSize(content.size());
}