2828import static com .google .gcloud .spi .StorageRpc .Option .IF_SOURCE_GENERATION_NOT_MATCH ;
2929import static com .google .gcloud .spi .StorageRpc .Option .IF_SOURCE_METAGENERATION_MATCH ;
3030import static com .google .gcloud .spi .StorageRpc .Option .IF_SOURCE_METAGENERATION_NOT_MATCH ;
31- import static java .net .HttpURLConnection .HTTP_NOT_FOUND ;
3231import static java .nio .charset .StandardCharsets .UTF_8 ;
3332
3433import com .google .api .services .storage .model .StorageObject ;
@@ -177,14 +176,7 @@ public BucketInfo get(String bucket, BucketGetOption... options) {
177176 new Callable <com .google .api .services .storage .model .Bucket >() {
178177 @ Override
179178 public com .google .api .services .storage .model .Bucket call () {
180- try {
181- return storageRpc .get (bucketPb , optionsMap );
182- } catch (StorageException ex ) {
183- if (ex .code () == HTTP_NOT_FOUND ) {
184- return null ;
185- }
186- throw ex ;
187- }
179+ return storageRpc .get (bucketPb , optionsMap );
188180 }
189181 }, options ().retryParams (), EXCEPTION_HANDLER );
190182 return answer == null ? null : BucketInfo .fromPb (answer );
@@ -206,14 +198,7 @@ public BlobInfo get(BlobId blob, BlobGetOption... options) {
206198 StorageObject storageObject = runWithRetries (new Callable <StorageObject >() {
207199 @ Override
208200 public StorageObject call () {
209- try {
210- return storageRpc .get (storedObject , optionsMap );
211- } catch (StorageException ex ) {
212- if (ex .code () == HTTP_NOT_FOUND ) {
213- return null ;
214- }
215- throw ex ;
216- }
201+ return storageRpc .get (storedObject , optionsMap );
217202 }
218203 }, options ().retryParams (), EXCEPTION_HANDLER );
219204 return storageObject == null ? null : BlobInfo .fromPb (storageObject );
@@ -525,28 +510,23 @@ public BatchResponse apply(BatchRequest batchRequest) {
525510 List <BatchResponse .Result <BlobInfo >> updates = transformBatchResult (
526511 toUpdate , response .updates , BlobInfo .FROM_PB_FUNCTION );
527512 List <BatchResponse .Result <BlobInfo >> gets = transformBatchResult (
528- toGet , response .gets , BlobInfo .FROM_PB_FUNCTION , HTTP_NOT_FOUND );
513+ toGet , response .gets , BlobInfo .FROM_PB_FUNCTION );
529514 return new BatchResponse (deletes , updates , gets );
530515 }
531516
532517 private <I , O extends Serializable > List <BatchResponse .Result <O >> transformBatchResult (
533518 Iterable <Tuple <StorageObject , Map <StorageRpc .Option , ?>>> request ,
534- Map <StorageObject , Tuple <I , StorageException >> results , Function <I , O > transform ,
535- int ... nullOnErrorCodes ) {
536- Set nullOnErrorCodesSet = Sets .newHashSet (Ints .asList (nullOnErrorCodes ));
519+ Map <StorageObject , Tuple <I , StorageException >> results , Function <I , O > transform ) {
537520 List <BatchResponse .Result <O >> response = Lists .newArrayListWithCapacity (results .size ());
538521 for (Tuple <StorageObject , ?> tuple : request ) {
539522 Tuple <I , StorageException > result = results .get (tuple .x ());
540- if (result .x () != null ) {
541- response .add (BatchResponse .Result .of (transform .apply (result .x ())));
523+ I object = result .x ();
524+ StorageException exception = result .y ();
525+ if (exception != null ) {
526+ response .add (new BatchResponse .Result <O >(exception ));
542527 } else {
543- StorageException exception = result .y ();
544- if (nullOnErrorCodesSet .contains (exception .code ())) {
545- //noinspection unchecked
546- response .add (BatchResponse .Result .<O >empty ());
547- } else {
548- response .add (new BatchResponse .Result <O >(exception ));
549- }
528+ response .add (object != null ?
529+ BatchResponse .Result .of (transform .apply (object )) : BatchResponse .Result .<O >empty ());
550530 }
551531 }
552532 return response ;
0 commit comments