Skip to content

Conversation

@nidhiii-27
Copy link

This PR adds the GetObjectChecksums.java sample to demonstrate how to use the new getObjectChecksums method to retrieve the CRC32C and MD5 checksums of a Google Cloud Storage object.

@nidhiii-27 nidhiii-27 requested review from a team and yoshi-approver as code owners January 13, 2026 07:10
@snippet-bot
Copy link

snippet-bot bot commented Jan 13, 2026

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: storage Issues related to the Cloud Storage API. labels Jan 13, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @nidhiii-27, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request adds a new Java sample that demonstrates how to programmatically retrieve CRC32C and MD5 checksums for objects stored in Google Cloud Storage. The sample utilizes the getObjectChecksums method and ChecksumRequestParams to provide a clear example of verifying data integrity by fetching these crucial metadata fields.

Highlights

  • New Sample Added: A new Java sample, GetObjectChecksums.java, has been introduced to demonstrate how to retrieve object checksums from Google Cloud Storage.
  • Checksum Retrieval: The sample specifically illustrates the use of the getObjectChecksums method to fetch CRC32C and MD5 checksums for a given GCS object.
  • Usage of ChecksumRequestParams: It showcases how to construct and apply Storage.ChecksumRequestParams to specify the desired checksum algorithms (CRC32C and MD5) when making a get request for a blob.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a new Java sample GetObjectChecksums.java to demonstrate fetching object checksums from Google Cloud Storage. The code is functionally correct, but I have a few suggestions to improve its adherence to Java best practices, such as making the utility class final, adding a private constructor, using more appropriate string formatting, and refining method signatures and output messages. These changes will improve the code's maintainability and readability.

import com.google.cloud.storage.StorageOptions;
import java.io.IOException;

public class GetObjectChecksums {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since this class only contains static methods, it should be marked as final to prevent it from being subclassed. It's also a good practice to add a private constructor to prevent instantiation. You can add private GetObjectChecksums() {} inside the class.

Suggested change
public class GetObjectChecksums {
public final class GetObjectChecksums {

import java.io.IOException;

public class GetObjectChecksums {
public static void getObjectChecksums(String bucketName, String objectName) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The throws IOException clause is unnecessary. The storage.get() method throws StorageException, which is a RuntimeException and does not need to be declared in the method signature. Removing it makes the signature more accurate.

Suggested change
public static void getObjectChecksums(String bucketName, String objectName) throws IOException {
public static void getObjectChecksums(String bucketName, String objectName) {

storage.get(BlobId.of(bucketName, objectName), Storage.BlobGetOption.checksumRequestParams(checksumRequestParams));

if (blobInfo == null) {
System.out.println("\nThere is no such object!\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The System.out.println() method already adds a newline character at the end of the output, so the trailing \n is redundant.

Suggested change
System.out.println("\nThere is no such object!\n");
System.out.println("\nThere is no such object!");

return;
}

System.out.println("Object: " + objectName + " in bucket: " + bucketName + " has CRC32C: " + blobInfo.getCrc32c() + " and MD5: " + blobInfo.getMd5());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using System.out.printf() can make this line more readable and is generally preferred over string concatenation, especially with multiple variables.

Suggested change
System.out.println("Object: " + objectName + " in bucket: " + bucketName + " has CRC32C: " + blobInfo.getCrc32c() + " and MD5: " + blobInfo.getMd5());
System.out.printf("Object: %s in bucket: %s has CRC32C: %s and MD5: %s%n", objectName, bucketName, blobInfo.getCrc32c(), blobInfo.getMd5());

@nidhiii-27 nidhiii-27 closed this Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants