Package com.google.common.hash

Examples of com.google.common.hash.HashCode


                        @Override
                        public long getValue() {
                            throw new UnsupportedOperationException();
                        }
                    }));
            HashCode hash = hasher.hash();

            // wrap into AbstractBlob for the SHA-256 memorization feature
            if (!(blob instanceof AbstractBlob)) {
                final Blob b = blob;
                blob = new AbstractBlob(hash) {
                    @Override
                    public long length() {
                        return b.length();
                    }
                    @Override
                    public InputStream getNewStream() {
                        return b.getNewStream();
                    }
                };
            }

            String id = hash.toString();
            blobs.put(id, blob);
            return id;
        } catch (IOException e) {
            throw new MicroKernelException("Failed to create a blob", e);
        }
View Full Code Here


    }
  }

  private static String getApiHash(File interfaceJar) throws IOException {
    byte[] fileBytes = Files.toByteArray(interfaceJar);
    HashCode hashCode = Hashing.sha1().hashBytes(fileBytes);
    return hashCode.toString();
  }
View Full Code Here

    public void close() {

    }

    public static BlobData build(ByteSource src) throws IOException {
        HashCode hashCode = src.hash(Hashing.md5());
        ByteString hash = ByteString.copyFrom(hashCode.asBytes());

        return new BlobData(src, hash);
    }
View Full Code Here

        if (localCache.exists()) {
            // TODO: Verify?
            log.debug("Using local cache file: {}", localCache);
        } else {
            try (TempFile localTemp = TempFile.in(this.localCacheDirTmp)) {
                HashCode md5;

                try (Sftp sftp = buildSftp(); InputStream is = sftp.open(remoteFile.getSshPath())) {
                    try (OutputStream os = new FileOutputStream(localTemp.getFile())) {
                        Hasher hasher = Hashing.md5().newHasher();
                        byte[] buffer = new byte[8192];
View Full Code Here

    assertExpectedBytes(readBytes);
  }

  public void testHash() throws IOException {
    HashCode expectedHash = Hashing.md5().hashBytes(expected);
    assertEquals(expectedHash, source.hash(Hashing.md5()));
  }
View Full Code Here

   }

   @Override
   public String putBlob(final String containerName, final Blob blob) throws IOException {
      byte[] payload;
      HashCode actualHashCode;
      HashingInputStream input = new HashingInputStream(Hashing.md5(), blob.getPayload().openStream());
      try {
         payload = ByteStreams.toByteArray(input);
         actualHashCode = input.hash();
         HashCode expectedHashCode = blob.getPayload().getContentMetadata().getContentMD5AsHashCode();
         if (expectedHashCode != null && !actualHashCode.equals(expectedHashCode)) {
            throw new IOException("MD5 hash code mismatch, actual: " + actualHashCode +
                  " expected: " + expectedHashCode);
         }
      } finally {
View Full Code Here

    /**
     * Default constructor.
     */
    ExceptionKey() {
        final HashFunction hashFunction = Hashing.md5();
        final HashCode hashCode = hashFunction.newHasher().putString(UUID.randomUUID().toString()).hash();
        this.key = hashCode.asInt();
        this.machineName = "UNKNOWN";
        try {
            InetAddress localMachine = java.net.InetAddress.getLocalHost();
            if (localMachine != null) {
                this.machineName = localMachine.getHostName();
View Full Code Here

   }

   @Test(groups = { "integration", "live" })
   public void testPutCorrectContentMD5() throws InterruptedException, IOException {
      byte[] payload = ByteStreams.toByteArray(createTestInput(1024));
      HashCode contentMD5 = md5().hashBytes(payload);
      putBlobWithMd5(payload, contentMD5);
   }
View Full Code Here

   }

   @Test(groups = { "integration", "live" })
   public void testPutIncorrectContentMD5() throws InterruptedException, IOException {
      byte[] payload = ByteStreams.toByteArray(createTestInput(1024));
      HashCode contentMD5 = md5().hashBytes(new byte[0]);
      try {
         putBlobWithMd5(payload, contentMD5);
         fail();
      } catch (HttpResponseException hre) {
         if (hre.getResponse().getStatusCode() != getIncorrectContentMD5StatusCode()) {
View Full Code Here

    }
  }

  private boolean haveSameContents(File file, final JarFile jar, final JarEntry entry) throws IOException {
    HashFunction hashFun = Hashing.md5();
    HashCode fileHash = Files.hash(file, hashFun);
    HashCode streamHash = ByteStreams.hash(new InputSupplier<InputStream>() {
      public InputStream getInput() throws IOException { return jar.getInputStream(entry); }
    }, hashFun);
    return fileHash.equals(streamHash);
  }
View Full Code Here

TOP

Related Classes of com.google.common.hash.HashCode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.