Search in sources :

Example 1 with BlobContainerListDetails

use of com.azure.storage.blob.models.BlobContainerListDetails in project ats-framework by Axway.

the class BlobStorageOperations method listContainers.

private PagedIterable<BlobContainerItem> listContainers(String containerNamePrefix, long retrieveTimeoutSeconds, boolean retrieveMetadata) {
    try {
        StringBuilder message = new StringBuilder();
        message.append("Listing");
        BlobContainerListDetails bcld = new BlobContainerListDetails();
        ListBlobContainersOptions lbco = new ListBlobContainersOptions();
        message.append(" containers");
        if (containerNamePrefix != null && !containerNamePrefix.isEmpty()) {
            message.append(" with prefix '" + containerNamePrefix + "'");
            lbco.setPrefix(containerNamePrefix);
        }
        if (log.isInfoEnabled()) {
            message.append(" ...");
            log.info(message.toString());
        }
        bcld.setRetrieveMetadata(retrieveMetadata);
        lbco.setDetails(bcld);
        if (retrieveTimeoutSeconds <= 0) {
            // just a little less than too much
            retrieveTimeoutSeconds = Integer.MAX_VALUE / 2;
        }
        PagedIterable<BlobContainerItem> blobContainers = serviceClient.listBlobContainers(lbco, Duration.ofSeconds(retrieveTimeoutSeconds));
        log.info("Successfully listed " + blobContainers.stream().count() + " containers.");
        return blobContainers;
    } catch (Exception e) {
        throw new AtsBlobStorageException("Could not list containers " + (!StringUtils.isNullOrEmpty(containerNamePrefix) ? "with prefix '" + containerNamePrefix + "'" : "") + " in " + retrieveTimeoutSeconds + " seconds", e);
    }
}
Also used : BlobContainerItem(com.azure.storage.blob.models.BlobContainerItem) ListBlobContainersOptions(com.azure.storage.blob.models.ListBlobContainersOptions) BlobContainerListDetails(com.azure.storage.blob.models.BlobContainerListDetails) BlobStorageException(com.azure.storage.blob.models.BlobStorageException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

BlobContainerItem (com.azure.storage.blob.models.BlobContainerItem)1 BlobContainerListDetails (com.azure.storage.blob.models.BlobContainerListDetails)1 BlobStorageException (com.azure.storage.blob.models.BlobStorageException)1 ListBlobContainersOptions (com.azure.storage.blob.models.ListBlobContainersOptions)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1