Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for selected fields to blob get and list#312
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
deecc14bea0157f11c05aba4bfa646b60df603d50caf7a08bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,7 +18,8 @@ | ||
| import static com.google.common.base.Preconditions.checkArgument; | ||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
| import static com.google.gcloud.storage.Blob.BlobSourceOption.convert; | ||
| import static com.google.gcloud.storage.Blob.BlobSourceOption.toSourceOptions; | ||
| import static com.google.gcloud.storage.Blob.BlobSourceOption.toGetOptions; | ||
| import com.google.common.base.Function; | ||
| import com.google.common.collect.Lists; | ||
| @@ -29,6 +30,7 @@ | ||
| import com.google.gcloud.storage.Storage.SignUrlOption; | ||
| import java.net.URL; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| @@ -56,7 +58,7 @@ private BlobSourceOption(StorageRpc.Option rpcOption) { | ||
| super(rpcOption, null); | ||
| } | ||
| private Storage.BlobSourceOption convert(BlobInfo blobInfo) { | ||
| private Storage.BlobSourceOption toSourceOptions(BlobInfo blobInfo) { | ||
| switch (rpcOption()) { | ||
| case IF_GENERATION_MATCH: | ||
| return Storage.BlobSourceOption.generationMatch(blobInfo.generation()); | ||
| @@ -71,6 +73,21 @@ private Storage.BlobSourceOption convert(BlobInfo blobInfo) { | ||
| } | ||
| } | ||
| private Storage.BlobGetOption toGetOption(BlobInfo blobInfo) { | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| switch (rpcOption()) { | ||
| case IF_GENERATION_MATCH: | ||
| return Storage.BlobGetOption.generationMatch(blobInfo.generation()); | ||
| case IF_GENERATION_NOT_MATCH: | ||
| return Storage.BlobGetOption.generationNotMatch(blobInfo.generation()); | ||
| case IF_METAGENERATION_MATCH: | ||
| return Storage.BlobGetOption.metagenerationMatch(blobInfo.metageneration()); | ||
| case IF_METAGENERATION_NOT_MATCH: | ||
| return Storage.BlobGetOption.metagenerationNotMatch(blobInfo.metageneration()); | ||
| default: | ||
| throw new AssertionError("Unexpected enum value"); | ||
| } | ||
| } | ||
| public static BlobSourceOption generationMatch() { | ||
| return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_MATCH); | ||
| } | ||
| @@ -87,11 +104,21 @@ public static BlobSourceOption metagenerationNotMatch() { | ||
| return new BlobSourceOption(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH); | ||
| } | ||
| static Storage.BlobSourceOption[] convert(BlobInfo blobInfo, BlobSourceOption... options) { | ||
| static Storage.BlobSourceOption[] toSourceOptions(BlobInfo blobInfo, | ||
| BlobSourceOption... options) { | ||
| Storage.BlobSourceOption[] convertedOptions = new Storage.BlobSourceOption[options.length]; | ||
| int index = 0; | ||
| for (BlobSourceOption option : options) { | ||
| convertedOptions[index++] = option.convert(blobInfo); | ||
| convertedOptions[index++] = option.toSourceOptions(blobInfo); | ||
| } | ||
| return convertedOptions; | ||
| } | ||
| static Storage.BlobGetOption[] toGetOptions(BlobInfo blobInfo, BlobSourceOption... options) { | ||
| Storage.BlobGetOption[] convertedOptions = new Storage.BlobGetOption[options.length]; | ||
| int index = 0; | ||
| for (BlobSourceOption option : options) { | ||
| convertedOptions[index++] = option.toGetOption(blobInfo); | ||
| } | ||
| return convertedOptions; | ||
| } | ||
| @@ -100,7 +127,7 @@ static Storage.BlobSourceOption[] convert(BlobInfo blobInfo, BlobSourceOption... | ||
| /** | ||
| * Constructs a {@code Blob} object for the provided {@code BlobInfo}. The storage service is used | ||
| * to issue requests. | ||
| * | ||
| * | ||
| * @param storage the storage service used for issuing requests | ||
| * @param info blob's info | ||
| */ | ||
| @@ -112,7 +139,7 @@ public Blob(Storage storage, BlobInfo info) { | ||
| /** | ||
| * Creates a {@code Blob} object for the provided bucket and blob names. Performs an RPC call to | ||
| * get the latest blob information. | ||
| * | ||
| * | ||
| * @param storage the storage service used for issuing requests | ||
| * @param bucket bucket's name | ||
| * @param blob blob's name | ||
| @@ -126,7 +153,7 @@ public static Blob load(Storage storage, String bucket, String blob) { | ||
| /** | ||
| * Creates a {@code Blob} object for the provided {@code blobId}. Performs an RPC call to get the | ||
| * latest blob information. | ||
| * | ||
| * | ||
| * @param storage the storage service used for issuing requests | ||
| * @param blobId blob's identifier | ||
| * @return the {@code Blob} object or {@code null} if not found. | ||
| @@ -159,7 +186,10 @@ public BlobId id() { | ||
| * @throws StorageException upon failure | ||
| */ | ||
| public boolean exists(BlobSourceOption... options) { | ||
| return storage.get(info.blobId(), convert(info, options)) != null; | ||
| int length = options.length; | ||
| Storage.BlobGetOption[] getOptions = Arrays.copyOf(toGetOptions(info, options), length + 1); | ||
| getOptions[length] = Storage.BlobGetOption.fields(); | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| return storage.get(info.blobId(), getOptions) != null; | ||
| } | ||
| /** | ||
| @@ -180,7 +210,7 @@ public byte[] content(Storage.BlobSourceOption... options) { | ||
| * @throws StorageException upon failure | ||
| */ | ||
| public Blob reload(BlobSourceOption... options) { | ||
| return new Blob(storage, storage.get(info.blobId(), convert(info, options))); | ||
| return new Blob(storage, storage.get(info.blobId(), toGetOptions(info, options))); | ||
| } | ||
| /** | ||
| @@ -224,7 +254,7 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) { | ||
| */ | ||
| public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) { | ||
| CopyRequest copyRequest = CopyRequest.builder().source(info.bucket(), info.name()) | ||
| .sourceOptions(convert(info, options)).target(targetBlob).build(); | ||
| .sourceOptions(toSourceOptions(info, options)).target(targetBlob).build(); | ||
| return storage.copy(copyRequest); | ||
| } | ||
| @@ -236,7 +266,7 @@ public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) { | ||
| * @throws StorageException upon failure | ||
| */ | ||
| public boolean delete(BlobSourceOption... options) { | ||
| return storage.delete(info.blobId(), convert(info, options)); | ||
| return storage.delete(info.blobId(), toSourceOptions(info, options)); | ||
| } | ||
| /** | ||
| @@ -275,7 +305,7 @@ public CopyWriter copyTo(String targetBucket, String targetBlob, BlobSourceOptio | ||
| * @throws StorageException upon failure | ||
| */ | ||
| public BlobReadChannel reader(BlobSourceOption... options) { | ||
| return storage.reader(info.blobId(), convert(info, options)); | ||
| return storage.reader(info.blobId(), toSourceOptions(info, options)); | ||
| } | ||
| /** | ||
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.