Package com.google.common.hash

Examples of com.google.common.hash.HashCode$BytesHashCode


   }

   @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

    runCommand(command);
  }

  private String calculateMd5sum(Path path) {
    try {
      HashCode hc = com.google.common.io.Files.hash(path.toFile(), Hashing.md5());

      return hc.toString();
    } catch (IOException e) {
      throw Throwables.propagate(e);
    }
  }
View Full Code Here

                        @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

      HashingInputStream his = null;
      try {
         Files.createParentDirs(outputFile);
         his = new HashingInputStream(Hashing.md5(), payload.openStream());
         Files.asByteSink(outputFile).writeFrom(his);
         HashCode actualHashCode = his.hash();
         HashCode expectedHashCode = payload.getContentMetadata().getContentMD5AsHashCode();
         if (expectedHashCode != null && !actualHashCode.equals(expectedHashCode)) {
            throw new IOException("MD5 hash code mismatch, actual: " + actualHashCode +
                  " expected: " + expectedHashCode);
         }
         payload.getContentMetadata().setContentMD5(actualHashCode);
View Full Code Here

   }

   @Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testCreateDirectory" })
   public void testListOptions() throws Exception {
      String data = "here is my data!";
      HashCode hashCode = Hashing.md5().hashString(data, UTF_8);
      createOrReplaceObject("object2", data, hashCode, "meta-value1");
      createOrReplaceObject("object3", data, hashCode, "meta-value1");
      createOrReplaceObject("object4", data, hashCode, "meta-value1");
      BoundedSet<? extends DirectoryEntry> r2 = getApi().listDirectory(privateDirectory, ListOptions.Builder.limit(1));
      assertEquals(r2.size(), 1);
View Full Code Here

      File payloadFile = File.createTempFile("testPutFileParallel", "png");
      createTestInput(32 * 1024).copyTo(Files.asByteSink(payloadFile));
     
      final Payload testPayload = Payloads.newFilePayload(payloadFile);
      final HashCode md5 = ByteStreams2.hashAndClose(testPayload.openStream(), md5());
      testPayload.getContentMetadata().setContentType("image/png");
     
      final AtomicInteger blobCount = new AtomicInteger();
      final String container = getContainerName();
      try {
View Full Code Here

   }

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

   }

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

   public void setUpResourcesOnThisThread(ITestContext testContext) throws Exception {
      super.setUpResourcesOnThisThread(testContext);
   }

   public void testMultipartSynchronously() throws InterruptedException, IOException {
      HashCode oneHundredOneConstitutionsMD5 = oneHundredOneConstitutions.hash(md5());
      String containerName = getContainerName();
      S3Object object = null;
      try {
         String key = "constitution.txt";
         String uploadId = getApi().initiateMultipartUpload(containerName,
                  ObjectMetadataBuilder.create().key(key).contentMD5(oneHundredOneConstitutionsMD5.asBytes()).build());
         byte[] buffer = oneHundredOneConstitutions.read();
         assertEquals(oneHundredOneConstitutions.size(), (long) buffer.length);

         Payload part1 = newByteArrayPayload(buffer);
         part1.getContentMetadata().setContentLength((long) buffer.length);
View Full Code Here

TOP

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

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.