Skip to content

Provide Storage.BlobListOption.defaultInstance() method for idiomatically listing every item in a GCS bucket #2667

Description

@joaoandremartins

I want to list every object in a bucket and add it to a list.

I want to use code similar to this:

		Storage.BlobListOption blobListOption = null;

		do {
			page = this.gcs.list(path, blobListOption);
			for (BlobInfo blob : page.getValues()) {
				blobs.add(blob);
			}
			blobListOption = Storage.BlobListOption.pageToken(page.getNextPageToken());
		} while (page.hasNextPage());

This code blows up with an NPE as expected. In order to make it work, I either need to duplicate the logic inside the while loop to get the first page with a this.gcs.list(path) call, or add a bogus Storage.BlobListOption, like Storage.BlobListOption.pageSize(50) instead of null at the beginning.

To support cases like this, there should be a Storage.BlobListOption factory for an empty Storage.BlobListOption.

Unless I'm missing anything?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions