GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Storage] Question about download object sample · Issue #1962 · googleapis/google-cloud-java

[Storage] Question about download object sample #1962

New issue
Copy link
New issue
Copy link
Closed
Closed
[Storage] Question about download object sample#1962
Copy link
Assignees
vam-google
Labels
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.

Description

@frankyn
frankyn
opened on Apr 21, 2017
Issue body actions

Hi,

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.

Activity

  1. vam-google commented on May 5, 2017

    @vam-google
    vam-google
    on May 5, 2017
    Contributor
    More actions

    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.

  2. shinfan
    added
    api: storageIssues related to the Cloud Storage API.
    type: questionRequest for information or clarification. Not an issue.
    on May 8, 2017
  3. shinfan commented on May 8, 2017

    @shinfan
    shinfan
    on May 8, 2017
    Contributor
    More actions

    @frankyn Does @vam-google answer your question? (If yes I will close this issue)

  4. frankyn commented on May 8, 2017

    @frankyn
    frankyn
    on May 8, 2017
    ContributorAuthor
    More actions

    Thanks @vam-google, is there reason for using exactly 1mb as the threshold?

  5. vam-google commented on May 8, 2017

    @vam-google
    vam-google
    on May 8, 2017
    Contributor
    More actions

    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.

  6. frankyn commented on May 8, 2017

    @frankyn
    frankyn
    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?

  7. tcoffee-google
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on May 22, 2017
  8. vam-google commented on May 24, 2017

    @vam-google
    vam-google
    on May 24, 2017
    Contributor
    More actions

    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.

  9. vam-google
    closed this as completedon May 24, 2017
  10. JustinBeckwith
    assigned
    vam-google
    on Feb 1, 2021
  11. chingor13
    added a commit that references this issue on Jan 22, 2026

    chore(main): release 2.32.0 (#1962)

    a16b249
  12. chingor13
    added 2 commits that reference this issue on Feb 20, 2026

    deps: update dependency org.apache.arrow:arrow-memory-netty to v11 (#…

    48abc75

    chore(main): release 2.31.0 (#1979)

    a1734e7
  13. lqiu96
    added a commit that references this issue on Mar 20, 2026

    chore(main): release 2.32.0 (#1962)

    5358dcb
  14. suztomo
    added a commit that references this issue on Mar 23, 2026

    deps: update dependency org.springframework.boot:spring-boot to v3.4.4 (

    a17e7d4
  15. meltsufin
    added 7 commits that reference this issue on Apr 29, 2026

    deps: update dependency com.google.cloud:google-cloud-core to v2.36.1 (…

    96c1c97

    chore(main): release 1.127.3 (#1959)

    e49cdc4

    chore(main): release 1.133.0 (#2206)

    a3b6539

    deps: update dependency com.google.cloud:google-cloud-core to v2.36.1 (…

    eb9a7d6

    chore(main): release 1.127.3 (#1959)

    fd73ca3

    chore(main): release 1.133.0 (#2206)

    1180af9

    deps: update dependency com.google.cloud:google-cloud-trace to v2.55.0 (

    46fd021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @vam-google
    vam-google

Labels

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.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.