@Override protected String getDigest(String value) { return Hashing.crc32c().hashString(value, StandardCharsets.UTF_8).toString(); }
/** * Verifies that the crc of an array of byte data matches the expected value. * * @param expectedCrc the expected crc value. * @param data the data to run the checksum on. */ private static void assertCrc(int expectedCrc, byte[] data) { int actualCrc = Hashing.crc32c().hashBytes(data).asInt(); assertEquals(expectedCrc, actualCrc); }
@Override public Blob create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options) { content = firstNonNull(content, EMPTY_BYTE_ARRAY); BlobInfo updatedInfo = blobInfo .toBuilder() .setMd5(BaseEncoding.base64().encode(Hashing.md5().hashBytes(content).asBytes())) .setCrc32c( BaseEncoding.base64() .encode(Ints.toByteArray(Hashing.crc32c().hashBytes(content).asInt()))) .build(); return internalCreate(updatedInfo, content, options); }
DigestOutputStream md5DigestOutputStream = new DigestOutputStream( nullOutputStream, MessageDigest.getInstance("MD5")); HashingOutputStream crc32cHashingOutputStream = new HashingOutputStream(Hashing.crc32c(), md5DigestOutputStream); ObjectsDownloadExample.downloadToOutputStream(storage, settings.getBucket(),
/** * Hash the given key in order to generate a uniform etag hash. * * @param key * Key which should be hashed * @return Computed hash */ public static String hash(String key) { return Hashing.crc32c().hashString(key.toString(), Charset.defaultCharset()).toString(); }
/** * Hash the given int in order to generate a uniform etag hash. * * @param key * Key which should be hashed * @return Computed hash */ public static String hash(int key) { return Hashing.crc32c().hashInt(key).toString(); }
/** * Returns checksum used for log. * * @param bytes data over which to compute the checksum * @return checksum of bytes */ static int getChecksum(byte[] bytes) { Hasher hasher = Hashing.crc32c().newHasher(); for (byte a : bytes) { hasher.putByte(a); } return hasher.hash().asInt(); }
public static int getChecksum(byte[] bytes) { Hasher hasher = Hashing.crc32c().newHasher(); for (byte a : bytes) { hasher.putByte(a); } return hasher.hash().asInt(); }
/** * Returns checksum used for log. * @param bytes data over which to compute the checksum * @return checksum of bytes */ public static int getChecksum(byte[] bytes) { Hasher hasher = Hashing.crc32c().newHasher(); for (byte a : bytes) { hasher.putByte(a); } return hasher.hash().asInt(); }
static int getChecksum(int num) { Hasher hasher = Hashing.crc32c().newHasher(); return hasher.putInt(num).hash().asInt(); } }
static int getChecksum(long num) { Hasher hasher = Hashing.crc32c().newHasher(); return hasher.putLong(num).hash().asInt(); }
static int getChecksum(int num) { Hasher hasher = Hashing.crc32c().newHasher(); return hasher.putInt(num).hash().asInt(); }
@Override public Blob create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options) { content = firstNonNull(content, EMPTY_BYTE_ARRAY); BlobInfo updatedInfo = blobInfo.toBuilder() .md5(BaseEncoding.base64().encode(Hashing.md5().hashBytes(content).asBytes())) .crc32c(BaseEncoding.base64().encode( Ints.toByteArray(Hashing.crc32c().hashBytes(content).asInt()))) .build(); return create(updatedInfo, new ByteArrayInputStream(content), options); }
@Override public Blob create(BlobInfo blobInfo, byte[] content, BlobTargetOption... options) { content = firstNonNull(content, EMPTY_BYTE_ARRAY); BlobInfo updatedInfo = blobInfo .toBuilder() .setMd5(BaseEncoding.base64().encode(Hashing.md5().hashBytes(content).asBytes())) .setCrc32c( BaseEncoding.base64() .encode(Ints.toByteArray(Hashing.crc32c().hashBytes(content).asInt()))) .build(); return internalCreate(updatedInfo, content, options); }
/** * Verifies that the crc of an array of byte data matches the expected value. * * @param expectedCrc the expected crc value. * @param data the data to run the checksum on. */ private static void assertCrc(int expectedCrc, byte[] data) { int actualCrc = Hashing.crc32c().hashBytes(data).asInt(); assertEquals(expectedCrc, actualCrc); }
@Override public synchronized void close() throws IOException { synchronized (InMemoryObjectEntry.this) { completedContents = toByteArray(); HashCode md5 = Hashing.md5().hashBytes(completedContents); HashCode crc32c = Hashing.crc32c().hashBytes(completedContents); writeStream = null; writeChannel = null; info = new GoogleCloudStorageItemInfo( info.getResourceId(), info.getCreationTime(), /* size= */ completedContents.length, /* location= */ null, /* storageClass= */ null, info.getContentType(), info.getContentEncoding(), info.getMetadata(), /* contentGeneration= */ 1, /* metaGeneration= */ 1, new VerificationAttributes(md5.asBytes(), Ints.toByteArray(crc32c.asInt()))); } } };