Package com.google.common.hash

Examples of com.google.common.hash.HashCode.asBytes()


    }

    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);
    }

    public static BlobData build(File file) throws IOException {
View Full Code Here


        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());
    }

    @Test(invocationCount = 100)
    public void testMoreThan16Bytes()
            throws Exception
View Full Code Here

        byte[] data = randomBytes(131);

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

        assertEquals(actual.getBytes(), expected.asBytes());
    }

    @Test(invocationCount = 100)
    public void testOffsetAndLength()
            throws Exception
View Full Code Here

        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());
    }

    @Test(invocationCount = 100)
    public void testNonDefaultSeed()
            throws Exception
View Full Code Here

        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());
    }

    @Test
    public void testTail()
            throws Exception
View Full Code Here

            byte[] data = randomBytes(50 + i);

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

            assertEquals(actual.getBytes(), expected.asBytes());
        }
    }

    @Test(invocationCount = 100)
    public void testLessThan16Bytes64()
View Full Code Here

            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

      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

     * @return the {@code ObjectId} generated from the string
     */
    public static ObjectId forString(final String strToHash) {
        Preconditions.checkNotNull(strToHash);
        HashCode hashCode = HASH_FUNCTION.hashString(strToHash, Charset.forName("UTF-8"));
        return new ObjectId(hashCode.asBytes(), false);
    }

    /**
     * Returns the value of this ObjectId's internal hash at the given index without having to go
     * through {@link #getRawValue()} and hence create excessive defensive copies of the byte array.
View Full Code Here

   /** @deprecated use {@link #getContentMD5AsHashCode()} instead. */
   @Deprecated
   @Override
   public byte[] getContentMD5() {
      HashCode hashCode = getContentMD5AsHashCode();
      return hashCode == null ? null : hashCode.asBytes();
   }

   @Override
   public HashCode getContentMD5AsHashCode() {
      return contentMD5;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.