File tree Expand file tree Collapse file tree
samples/snippets/src/main/java/com/example/storage/object Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .example .storage .object ;
2+
3+ import com .google .cloud .storage .BlobId ;
4+ import com .google .cloud .storage .BlobInfo ;
5+ import com .google .cloud .storage .Storage ;
6+ import com .google .cloud .storage .Storage .ChecksumRequestParams ;
7+ import com .google .cloud .storage .StorageOptions ;
8+ import java .io .IOException ;
9+
10+ public class GetObjectChecksums {
11+ public static void getObjectChecksums (String bucketName , String objectName ) throws IOException {
12+ // [START storage_get_object_checksums]
13+ // The ID of your GCS bucket
14+ // String bucketName = "your-bucket-name";
15+ // The ID of your GCS object
16+ // String objectName = "your-object-name";
17+
18+ Storage storage = StorageOptions .getDefaultInstance ().getService ();
19+
20+ ChecksumRequestParams checksumRequestParams =
21+ Storage .ChecksumRequestParams .newBuilder ().setChecksumAlgorithm (Storage .ChecksumAlgorithm .CRC32C , Storage .ChecksumAlgorithm .MD5 ).build ();
22+
23+ BlobInfo blobInfo =
24+ storage .get (BlobId .of (bucketName , objectName ), Storage .BlobGetOption .checksumRequestParams (checksumRequestParams ));
25+
26+ if (blobInfo == null ) {
27+ System .out .println ("\n There is no such object!\n " );
28+ return ;
29+ }
30+
31+ System .out .println ("Object: " + objectName + " in bucket: " + bucketName + " has CRC32C: " + blobInfo .getCrc32c () + " and MD5: " + blobInfo .getMd5 ());
32+ // [END storage_get_object_checksums]
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments