1919import static com .google .common .base .Preconditions .checkArgument ;
2020import static com .google .common .base .Preconditions .checkNotNull ;
2121import static com .google .gcloud .storage .Blob .BlobSourceOption .convert ;
22+ import static com .google .gcloud .storage .Blob .BlobSourceOption .toGetOptions ;
2223
2324import com .google .common .base .Function ;
2425import com .google .common .collect .Lists ;
2930import com .google .gcloud .storage .Storage .SignUrlOption ;
3031
3132import java .net .URL ;
33+ import java .util .Arrays ;
3234import java .util .Collections ;
3335import java .util .List ;
3436import java .util .Objects ;
@@ -71,6 +73,21 @@ private Storage.BlobSourceOption convert(BlobInfo blobInfo) {
7173 }
7274 }
7375
76+ private Storage .BlobGetOption toGetOption (BlobInfo blobInfo ) {
77+ switch (rpcOption ()) {
78+ case IF_GENERATION_MATCH :
79+ return Storage .BlobGetOption .generationMatch (blobInfo .generation ());
80+ case IF_GENERATION_NOT_MATCH :
81+ return Storage .BlobGetOption .generationNotMatch (blobInfo .generation ());
82+ case IF_METAGENERATION_MATCH :
83+ return Storage .BlobGetOption .metagenerationMatch (blobInfo .metageneration ());
84+ case IF_METAGENERATION_NOT_MATCH :
85+ return Storage .BlobGetOption .metagenerationNotMatch (blobInfo .metageneration ());
86+ default :
87+ throw new AssertionError ("Unexpected enum value" );
88+ }
89+ }
90+
7491 public static BlobSourceOption generationMatch () {
7592 return new BlobSourceOption (StorageRpc .Option .IF_GENERATION_MATCH );
7693 }
@@ -95,6 +112,15 @@ static Storage.BlobSourceOption[] convert(BlobInfo blobInfo, BlobSourceOption...
95112 }
96113 return convertedOptions ;
97114 }
115+
116+ static Storage .BlobGetOption [] toGetOptions (BlobInfo blobInfo , BlobSourceOption ... options ) {
117+ Storage .BlobGetOption [] convertedOptions = new Storage .BlobGetOption [options .length ];
118+ int index = 0 ;
119+ for (BlobSourceOption option : options ) {
120+ convertedOptions [index ++] = option .toGetOption (blobInfo );
121+ }
122+ return convertedOptions ;
123+ }
98124 }
99125
100126 /**
@@ -159,7 +185,10 @@ public BlobId id() {
159185 * @throws StorageException upon failure
160186 */
161187 public boolean exists (BlobSourceOption ... options ) {
162- return storage .get (info .blobId (), convert (info , options )) != null ;
188+ int length = options .length ;
189+ Storage .BlobGetOption [] getOptions = Arrays .copyOf (toGetOptions (info , options ), length + 1 );
190+ getOptions [length ] = Storage .BlobGetOption .fields ();
191+ return storage .get (info .blobId (), getOptions ) != null ;
163192 }
164193
165194 /**
@@ -180,7 +209,7 @@ public byte[] content(Storage.BlobSourceOption... options) {
180209 * @throws StorageException upon failure
181210 */
182211 public Blob reload (BlobSourceOption ... options ) {
183- return new Blob (storage , storage .get (info .blobId (), convert (info , options )));
212+ return new Blob (storage , storage .get (info .blobId (), toGetOptions (info , options )));
184213 }
185214
186215 /**
0 commit comments