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:org.codehaus.httpcache4j.cache.FileManager.java

public synchronized File resolve(URI uri) {
    String uriHex = Hashing.md5().hashString(uri.toString(), Charsets.UTF_8).toString().trim();
    String distribution = uriHex.substring(0, 2);
    return new File(new File(baseDirectory, distribution), uriHex);
}

From source file:com.cinchapi.concourse.cache.ReferenceCache.java

/**
 * Return a unique identifier for a group of {@code args}.
 * /* w  ww  .  ja va 2 s.c  o m*/
 * @param args
 * @return the identifier.
 */
private HashCode getCacheKey(Object... args) {
    StringBuilder key = new StringBuilder();
    for (Object o : args) {
        key.append(o.hashCode());
        key.append(o.getClass().getName());
    }
    return Hashing.md5().hashUnencodedChars(key.toString());
}

From source file:org.openscoring.service.ModelRegistry.java

@SuppressWarnings(value = { "resource" })
public Model load(InputStream is) throws Exception {
    CountingInputStream countingIs = new CountingInputStream(is);

    HashingInputStream hashingIs = new HashingInputStream(Hashing.md5(), countingIs);

    ModelEvaluator<?> evaluator = unmarshal(hashingIs, this.validate);

    PMML pmml = evaluator.getPMML();//from w  w  w .ja va2  s  .com

    for (Class<? extends Visitor> visitorClazz : this.visitorClazzes) {
        Visitor visitor = visitorClazz.newInstance();

        visitor.applyTo(pmml);
    }

    evaluator.verify();

    Model model = new Model(evaluator);
    model.putProperty(Model.PROPERTY_FILE_SIZE, countingIs.getCount());
    model.putProperty(Model.PROPERTY_FILE_MD5SUM, (hashingIs.hash()).toString());

    return model;
}

From source file:com.qubole.rubix.bookkeeper.BookKeeper.java

@Override
public List<com.qubole.rubix.bookkeeper.Location> getCacheStatus(String remotePath, long fileLength,
        long lastModified, long startBlock, long endBlock, int clusterType) throws TException {
    initializeClusterManager(clusterType);

    if (nodeName == null) {
        log.error("Node name is null for Cluster Type" + ClusterType.findByValue(clusterType));
        return null;
    }//from   w w w .ja  va 2 s .co m

    Set<Long> localSplits = new HashSet<>();
    long blockNumber = 0;

    for (long i = 0; i < fileLength; i = i + splitSize) {
        long end = i + splitSize;
        if (end > fileLength) {
            end = fileLength;
        }
        String key = remotePath + i + end;
        HashFunction hf = Hashing.md5();
        HashCode hc = hf.hashString(key, Charsets.UTF_8);
        int nodeIndex = Hashing.consistentHash(hc, nodeListSize);
        if (nodeIndex == currentNodeIndex) {
            localSplits.add(blockNumber);
        }
        blockNumber++;
    }

    FileMetadata md;
    try {
        md = fileMetadataCache.get(remotePath,
                new CreateFileMetadataCallable(remotePath, fileLength, lastModified, conf));
        if (md.getLastModified() != lastModified) {
            invalidate(remotePath);
            md = fileMetadataCache.get(remotePath,
                    new CreateFileMetadataCallable(remotePath, fileLength, lastModified, conf));
        }
    } catch (ExecutionException e) {
        log.error(String.format("Could not fetch Metadata for %s : %s", remotePath,
                Throwables.getStackTraceAsString(e)));
        throw new TException(e);
    }
    endBlock = setCorrectEndBlock(endBlock, fileLength, remotePath);
    List<Location> blocksInfo = new ArrayList<>((int) (endBlock - startBlock));
    int blockSize = CacheConfig.getBlockSize(conf);

    for (long blockNum = startBlock; blockNum < endBlock; blockNum++) {
        totalRequests++;
        long split = (blockNum * blockSize) / splitSize;

        if (md.isBlockCached(blockNum)) {
            blocksInfo.add(Location.CACHED);
            cachedRequests++;
        } else {
            if (localSplits.contains(split)) {
                blocksInfo.add(Location.LOCAL);
                remoteRequests++;
            } else {
                blocksInfo.add(Location.NON_LOCAL);
            }
        }
    }

    return blocksInfo;
}

From source file:org.dspace.ctask.replicate.store.LocalObjectStore.java

@Override
public String objectAttribute(String group, String id, String attrName) throws IOException {
    Path archFile = Paths.get(storeDir, group, id);
    if ("checksum".equals(attrName)) {
        return com.google.common.io.Files.hash(archFile.toFile(), Hashing.md5()).toString();
        //return Utils.checksum(archFile, "MD5");
    } else if ("sizebytes".equals(attrName)) {
        return String.valueOf(Files.size(archFile));
    } else if ("modified".equals(attrName)) {
        return String.valueOf(Files.getLastModifiedTime(archFile).toMillis());
    }//ww  w .  ja  v a 2 s  . c  om
    return null;
}

From source file:org.apache.usergrid.management.importer.S3Upload.java

public void copyToS3(String accessKey, String secretKey, String bucketName, List<String> filenames)
        throws FileNotFoundException {

    Properties overrides = new Properties();
    overrides.setProperty("s3" + ".identity", accessKey);
    overrides.setProperty("s3" + ".credential", secretKey);

    final Iterable<? extends Module> MODULES = ImmutableSet.of(new JavaUrlHttpCommandExecutorServiceModule(),
            new Log4JLoggingModule(), new NettyPayloadModule());

    BlobStoreContext context = ContextBuilder.newBuilder("s3").credentials(accessKey, secretKey)
            .modules(MODULES).overrides(overrides).buildView(BlobStoreContext.class);

    // Create Container (the bucket in s3)
    try {//from   w  w w. j  a  v a  2  s  .c om
        BlobStore blobStore = context.getBlobStore();
        if (blobStore.createContainerInLocation(null, bucketName)) {
            logger.info("Created bucket " + bucketName);
        }
    } catch (Exception ex) {
        throw new RuntimeException("Could not create bucket", ex);
    }

    Iterator<String> fileNameIterator = filenames.iterator();

    while (fileNameIterator.hasNext()) {

        String filename = fileNameIterator.next();
        File uploadFile = new File(filename);

        try {
            BlobStore blobStore = context.getBlobStore();

            // need this for JClouds 1.7.x:
            //                BlobBuilder.PayloadBlobBuilder blobBuilder =  blobStore.blobBuilder( filename )
            //                    .payload( uploadFile ).calculateMD5().contentType( "application/json" );

            // needed for JClouds 1.8.x:
            BlobBuilder blobBuilder = blobStore.blobBuilder(filename).payload(uploadFile)
                    .contentMD5(Files.hash(uploadFile, Hashing.md5())).contentType("application/json");

            Blob blob = blobBuilder.build();

            final String uploadedFile = blobStore.putBlob(bucketName, blob, PutOptions.Builder.multipart());

            //wait for the file to finish uploading
            Thread.sleep(4000);

            logger.info("Uploaded file name={} etag={}", filename, uploadedFile);
        } catch (Exception e) {
            logger.error("Error uploading to blob store. File: " + filename, e);
        }
    }
}

From source file:com.facebook.buck.rules.Manifest.java

@VisibleForTesting
protected static HashCode hashSourcePathGroup(FileHashCache fileHashCache, SourcePathResolver resolver,
        ImmutableList<SourcePath> paths) throws IOException {
    if (paths.size() == 1) {
        return hashSourcePath(paths.asList().get(0), fileHashCache, resolver);
    }/*from   ww  w  . j a v  a2  s. co  m*/
    Hasher hasher = Hashing.md5().newHasher();
    for (SourcePath path : paths) {
        hasher.putBytes(hashSourcePath(path, fileHashCache, resolver).asBytes());
    }
    return hasher.hash();
}

From source file:de.fhg.iais.cortex.rest.resources.BinaryResource.java

@Inject
//    public BinaryResource(IAccessService accessService, Provider<Role> roleProvider, @Named("auth.aas.blacklistedProvider") String blacklist) {
//        super(accessService, roleProvider, blacklist);
public BinaryResource(IAccessService accessService, ISearchService searchService, Provider<Role> roleProvider,
        @Named("auth.aas.blacklistedProvider") String blacklist) {
    super(searchService, roleProvider, blacklist);

    this.accessService = accessService;

    this.mimeUtil = new MimeUtil2();
    this.mimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.ExtensionMimeDetector");
    this.mimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");

    this.hf = Hashing.md5();
}

From source file:com.peppe130.rominstaller.core.CheckFile.java

@Override
protected Boolean doInBackground(String... mCheck) {

    String mModel = (String.format(Utils.ACTIVITY.getString(R.string.device_model), Utils.GetDeviceModel()));

    StringBuilder sbUpdate = new StringBuilder();

    updateResult((long) 1200, sbUpdate.append(mModel).toString());

    if (ControlCenter.TRIAL_MODE) {

        updateResult((long) 2500, sbUpdate.append(Utils.ACTIVITY.getString(R.string.calculating_md5))
                .append(" (Fake)").toString());

        updateResult((long) 5000, sbUpdate.append(Utils.ACTIVITY.getString(R.string.initialized)).toString());

        return true;

    } else {// w  w  w  . j av a  2  s. co m

        publishProgress(sbUpdate.append(Utils.ACTIVITY.getString(R.string.calculating_md5)).toString());

        try {

            mMD5 = Files.hash(Utils.GetZipFile(), Hashing.md5()).toString();

        } catch (IOException e) {

            e.printStackTrace();

        }

        try {

            Thread.sleep(2000);

        } catch (InterruptedException e) {

            e.printStackTrace();

        }

        if ((Utils.GetZipFile().exists())
                && (Arrays.asList(ControlCenter.ROM_MD5_LIST).contains(mMD5.toUpperCase())
                        || Arrays.asList(ControlCenter.ROM_MD5_LIST).contains(mMD5.toLowerCase()))) {

            updateResult((long) 5000,
                    sbUpdate.append(Utils.ACTIVITY.getString(R.string.initialized)).toString());

            return true;

        }

    }

    return false;

}

From source file:org.tzi.use.uml.ocl.type.MessageType.java

private int generateHash() {
    HashFunction hf = Hashing.md5();
    HashCode hc = hf.newHasher().putBoolean(isReferencingSignal())
            .putString(isReferencingOperation() ? this.referredOperation.name() : "", Charsets.UTF_8)
            .putString(isReferencingSignal() ? this.referredSignal.name() : "", Charsets.UTF_8).hash();

    return hc.asInt();
}