public static StorageObjectSummary createFromAzureListBlobItem ( ListBlobItem listBlobItem ) throws StorageProviderException { String location , key , md5 ; long size ; // Retrieve the BLOB properties that we need for the Summary // Azure Storage stores metadata inside each BLOB, therefore the listBlobItem // will point us to the underlying BLOB and will get the properties from it // During the process the Storage Client could fail, hence we need to wrap the // get calls in try/catch and handle possible exceptions try { location = listBlobItem . getContainer ( ) . getName ( ) ; CloudBlob cloudBlob = ( CloudBlob ) listBlobItem ; key = cloudBlob . getName ( ) ; BlobProperties blobProperties = cloudBlob . getProperties ( ) ; // the content md5 property is not always the actual md5 of the file. But for here, it's only // used for skipping file on PUT command, hense is ok. md5 = convertBase64ToHex ( blobProperties . getContentMD5 ( ) ) ; size = blobProperties . getLength ( ) ; } catch ( URISyntaxException | StorageException ex ) { // This should only happen if somehow we got here with and invalid URI (it should never happen) // ...or there is a Storage service error. Unlike S3, Azure fetches metadata from the BLOB itself, // and its a lazy operation throw new StorageProviderException ( ex ) ; } return new StorageObjectSummary ( location , key , md5 , size ) ; }
Contructs a StorageObjectSummary object from Azure BLOB properties Using factory methods to create these objects since Azure can throw while retrieving the BLOB properties