GeezerVison is showing github.com — [Storage] Question about download object sample · Issue #1962 · googleapis/google-cloud-java
[Storage] Question about download object sample #1962Labels api: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue. DescriptionHi,
I'm trying to understand why the download object sample has a condition for an object size of 1 mb and larger objects. Why not just simplify the simplify it down to:
Blob blob = storage.get(blobId);
if (blob == null) {
System.out.println("No such object");
return;
}
PrintStream writeTo = System.out;
if (downloadTo != null) {
writeTo = new PrintStream(new FileOutputStream(downloadTo.toFile()));
}
// Blob is small read all its content in one request
byte[] content = blob.getContent();
writeTo.write(content);
if (downloadTo == null) {
writeTo.println();
} else {
writeTo.close();
}
Thank you. Activityvam-google commented on May 5, 2017 This is to demonstrate the recommended way of handling small objects and handling large objects
This is an example code and its goal is to demonstrate how the libraries should be used, ideally showing the best practices.
Theoretically an object can become bigger than available memory so the "easy way" of calling byte[] content = blob.getContent() will just crush the program. shinfan commented on May 8, 2017 frankyn commented on May 8, 2017 ContributorAuthor More actions Thanks @vam-google, is there reason for using exactly 1mb as the threshold? vam-google commented on May 8, 2017 I don't think so, it is just a "rasonable" round number, good for examples. Strictly speaking, it is not even a 1MB, as it is 1,000,000, while 1MB = 2^20 = 1,048,576.
[Edit] Apparently 1MB is strictly 1,000,000, so sorry for confusion. frankyn commented on May 8, 2017 ContributorAuthor More actions Mebibyte versus Megabyte. Thank you! I just wanted to make sure, because it's a magic number in the sample code and can be confusing.
Is there a rational to use the magic number 1_000_000 instead of a variable? vam-google commented on May 24, 2017 I don't think there is any specific rational behind that, probably it was just simpler to write the sample in this way.
Closing the issue.
MetadataMetadataapi: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue. DevelopmentNo branches or pull requestsIssue actions
|