-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add GetObjectChecksums.java sample #10221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| public class GetObjectChecksums { | |
| public final class GetObjectChecksums { |
| import java.io.IOException; | ||
|
|
||
| public class GetObjectChecksums { | ||
| public static void getObjectChecksums(String bucketName, String objectName) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return; | ||
| } | ||
|
|
||
| System.out.println("Object: " + objectName + " in bucket: " + bucketName + " has CRC32C: " + blobInfo.getCrc32c() + " and MD5: " + blobInfo.getMd5()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using System.out.printf() can make this line more readable and is generally preferred over string concatenation, especially with multiple variables.
| 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()); |
This PR adds the GetObjectChecksums.java sample to demonstrate how to use the new
getObjectChecksumsmethod to retrieve the CRC32C and MD5 checksums of a Google Cloud Storage object.