Package com.google.common.hash

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


    public void testLessThan16Bytes()
            throws Exception
    {
        byte[] data = randomBytes(ThreadLocalRandom.current().nextInt(16));

        HashCode expected = Hashing.murmur3_128().hashBytes(data);
        Slice actual = Murmur3.hash(Slices.wrappedBuffer(data));

        assertEquals(actual.getBytes(), expected.asBytes());
    }
View Full Code Here


    public void testMoreThan16Bytes()
            throws Exception
    {
        byte[] data = randomBytes(131);

        HashCode expected = Hashing.murmur3_128().hashBytes(data);
        Slice actual = Murmur3.hash(Slices.wrappedBuffer(data));

        assertEquals(actual.getBytes(), expected.asBytes());
    }
View Full Code Here

        byte[] data = randomBytes(131);

        int offset = 13;
        int length = 55;

        HashCode expected = Hashing.murmur3_128().hashBytes(data, offset, length);
        Slice actual = Murmur3.hash(Slices.wrappedBuffer(data), offset, length);

        assertEquals(actual.getBytes(), expected.asBytes());
    }
View Full Code Here

    {
        byte[] data = randomBytes(131);

        int seed = 123456789;

        HashCode expected = Hashing.murmur3_128(seed).hashBytes(data);
        Slice actual = Murmur3.hash(seed, Slices.wrappedBuffer(data), 0, data.length);

        assertEquals(actual.getBytes(), expected.asBytes());
    }
View Full Code Here

            throws Exception
    {
        for (int i = 0; i < 16; i++) {
            byte[] data = randomBytes(50 + i);

            HashCode expected = Hashing.murmur3_128().hashBytes(data);
            Slice actual = Murmur3.hash(Slices.wrappedBuffer(data));

            assertEquals(actual.getBytes(), expected.asBytes());
        }
    }
View Full Code Here

   @Test
   public void testBuildTreeHashFromMap() throws IOException {
      Builder<Integer, HashCode> map = ImmutableMap.<Integer, HashCode>builder();
      map.put(2, HashCode.fromString("9bc1b2a288b26af7257a36277ae3816a7d4f16e89c1e7e77d0a5c48bad62b360"));
      map.put(1, HashCode.fromString("9bc1b2a288b26af7257a36277ae3816a7d4f16e89c1e7e77d0a5c48bad62b360"));
      HashCode treehash = TreeHash.buildTreeHashFromMap(map.build());
      assertThat(treehash).isEqualTo(HashCode.fromString("560c2c9333c719cb00cfdffee3ba293db17f58743cdd1f7e4055373ae6300afa"));
   }
View Full Code Here

      String date = request.getFirstHeaderOrNull(GlacierHeaders.ALTERNATE_DATE);
      String dateWithoutTimestamp = formatDateWithoutTimestamp(date);
      String method = request.getMethod();
      String endpoint = request.getEndpoint().getRawPath();
      String credentialScope = buildCredentialScope(dateWithoutTimestamp);
      HashCode hashedPayload = buildHashedPayload(request);

      // Task 1: Create a Canonical Request For Signature Version 4.
      HashCode hashedCanonicalRequest = buildHashedCanonicalRequest(method, endpoint, hashedPayload,
            canonicalizedHeadersString, signedHeaders);

      // Task 2: Create a String to Sign for Signature Version 4.
      String stringToSign = createStringToSign(date, credentialScope, hashedCanonicalRequest);
View Full Code Here

   private static HashCode hashList(Collection<HashCode> hashList) {
      Builder<HashCode> result = ImmutableList.builder();
      while (hashList.size() > 1) {
         //Hash pairs of values and add them to the result list.
         for (Iterator<HashCode> it = hashList.iterator(); it.hasNext();) {
            HashCode hc1 = it.next();
            if (it.hasNext()) {
                HashCode hc2 = it.next();
                result.add(Hashing.sha256().newHasher()
                      .putBytes(hc1.asBytes())
                      .putBytes(hc2.asBytes())
                      .hash());
            } else {
               result.add(hc1);
            }
         }
View Full Code Here

      long partSizeInMb = 1;
      String uploadId = api.initiateMultipartUpload(VAULT_NAME1, partSizeInMb);
      try {
         assertThat(api.listMultipartUploads(VAULT_NAME1)).extracting("multipartUploadId").contains(uploadId);

         HashCode part1 = api.uploadPart(VAULT_NAME1, uploadId,
               ContentRange.fromPartNumber(0, partSizeInMb), buildPayload(partSizeInMb * MiB));
         HashCode part2 = api.uploadPart(VAULT_NAME1, uploadId,
               ContentRange.fromPartNumber(1, partSizeInMb), buildPayload(partSizeInMb * MiB));
         assertThat(part1).isNotNull();
         assertThat(part2).isNotNull();
         assertThat(api.listParts(VAULT_NAME1, uploadId)).extracting("treeHash").containsExactly(part1, part2);
      } finally {
View Full Code Here

      MockResponse mr = buildBaseResponse(201);
      mr.addHeader(HttpHeaders.LOCATION, ARCHIVE_LOCATION);
      mr.addHeader(GlacierHeaders.ARCHIVE_ID, ARCHIVE_ID);
      server.enqueue(mr);

      HashCode partHashcode = HashCode.fromString("9bc1b2a288b26af7257a36277ae3816a7d4f16e89c1e7e77d0a5c48bad62b360");
      ImmutableMap<Integer, HashCode> map = ImmutableMap.of(
            1, partHashcode,
            2, partHashcode,
            3, partHashcode,
            4, partHashcode);
View Full Code Here

TOP

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

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.