public static GoogleCloudStorageItemInfo createItemInfoForStorageObject ( StorageResourceId resourceId , StorageObject object ) { Preconditions . checkArgument ( resourceId != null , "resourceId must not be null" ) ; Preconditions . checkArgument ( object != null , "object must not be null" ) ; Preconditions . checkArgument ( resourceId . isStorageObject ( ) , "resourceId must be a StorageObject. resourceId: %s" , resourceId ) ; Preconditions . checkArgument ( resourceId . getBucketName ( ) . equals ( object . getBucket ( ) ) , "resourceId.getBucketName() must equal object.getBucket(): '%s' vs '%s'" , resourceId . getBucketName ( ) , object . getBucket ( ) ) ; Preconditions . checkArgument ( resourceId . getObjectName ( ) . equals ( object . getName ( ) ) , "resourceId.getObjectName() must equal object.getName(): '%s' vs '%s'" , resourceId . getObjectName ( ) , object . getName ( ) ) ; Map < String , byte [ ] > decodedMetadata = object . getMetadata ( ) == null ? null : decodeMetadata ( object . getMetadata ( ) ) ; byte [ ] md5Hash = null ; byte [ ] crc32c = null ; if ( ! Strings . isNullOrEmpty ( object . getCrc32c ( ) ) ) { crc32c = BaseEncoding . base64 ( ) . decode ( object . getCrc32c ( ) ) ; } if ( ! Strings . isNullOrEmpty ( object . getMd5Hash ( ) ) ) { md5Hash = BaseEncoding . base64 ( ) . decode ( object . getMd5Hash ( ) ) ; } // GCS API does not make available location and storage class at object level at present // (it is same for all objects in a bucket). Further, we do not use the values for objects. // The GoogleCloudStorageItemInfo thus has 'null' for location and storage class. return new GoogleCloudStorageItemInfo ( resourceId , object . getUpdated ( ) . getValue ( ) , object . getSize ( ) . longValue ( ) , /* location= */ null , /* storageClass= */ null , object . getContentType ( ) , object . getContentEncoding ( ) , decodedMetadata , object . getGeneration ( ) , object . getMetageneration ( ) , new VerificationAttributes ( md5Hash , crc32c ) ) ; }
Helper for converting a StorageResourceId + StorageObject into a GoogleCloudStorageItemInfo .