当前位置: 首页>>代码示例>>Java>>正文


Java CloudBlobClient.getContainerReference方法代码示例

本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlobClient.getContainerReference方法的典型用法代码示例。如果您正苦于以下问题:Java CloudBlobClient.getContainerReference方法的具体用法?Java CloudBlobClient.getContainerReference怎么用?Java CloudBlobClient.getContainerReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.microsoft.azure.storage.blob.CloudBlobClient的用法示例。


在下文中一共展示了CloudBlobClient.getContainerReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteFiles

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
@Override
public void deleteFiles(String account, LocationMode mode, String container, String path) throws URISyntaxException, StorageException {
    logger.trace("delete files container [{}], path [{}]", container, path);

    // Container name must be lower case.
    CloudBlobClient client = this.getSelectedClient(account, mode);
    CloudBlobContainer blobContainer = client.getContainerReference(container);
    SocketAccess.doPrivilegedVoidException(() -> {
        if (blobContainer.exists()) {
            // We list the blobs using a flat blob listing mode
            for (ListBlobItem blobItem : blobContainer.listBlobs(path, true)) {
                String blobName = blobNameFromUri(blobItem.getUri());
                logger.trace("removing blob [{}] full URI was [{}]", blobName, blobItem.getUri());
                deleteBlob(account, mode, container, blobName);
            }
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:AzureStorageServiceImpl.java

示例2: listBlobsByPrefix

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
@Override
public Map<String, BlobMetaData> listBlobsByPrefix(String account, LocationMode mode, String container, String keyPath, String prefix) throws URISyntaxException, StorageException {
    // NOTE: this should be here: if (prefix == null) prefix = "";
    // however, this is really inefficient since deleteBlobsByPrefix enumerates everything and
    // then does a prefix match on the result; it should just call listBlobsByPrefix with the prefix!

    logger.debug("listing container [{}], keyPath [{}], prefix [{}]", container, keyPath, prefix);
    MapBuilder<String, BlobMetaData> blobsBuilder = MapBuilder.newMapBuilder();
    CloudBlobClient client = this.getSelectedClient(account, mode);
    CloudBlobContainer blobContainer = client.getContainerReference(container);

    SocketAccess.doPrivilegedVoidException(() -> {
        if (blobContainer.exists()) {
            for (ListBlobItem blobItem : blobContainer.listBlobs(keyPath + (prefix == null ? "" : prefix))) {
                URI uri = blobItem.getUri();
                logger.trace("blob url [{}]", uri);

                // uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/
                // this requires 1 + container.length() + 1, with each 1 corresponding to one of the /
                String blobPath = uri.getPath().substring(1 + container.length() + 1);

                CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobPath);

                // fetch the blob attributes from Azure (getBlockBlobReference does not do this)
                // this is needed to retrieve the blob length (among other metadata) from Azure Storage
                blob.downloadAttributes();

                BlobProperties properties = blob.getProperties();
                String name = blobPath.substring(keyPath.length());
                logger.trace("blob url [{}], name [{}], size [{}]", uri, name, properties.getLength());
                blobsBuilder.put(name, new PlainBlobMetaData(name, properties.getLength()));
            }
        }
    });

    return blobsBuilder.immutableMap();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:AzureStorageServiceImpl.java

示例3: moveBlob

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
@Override
public void moveBlob(String account, LocationMode mode, String container, String sourceBlob, String targetBlob) throws URISyntaxException, StorageException {
    logger.debug("moveBlob container [{}], sourceBlob [{}], targetBlob [{}]", container, sourceBlob, targetBlob);

    CloudBlobClient client = this.getSelectedClient(account, mode);
    CloudBlobContainer blobContainer = client.getContainerReference(container);
    CloudBlockBlob blobSource = blobContainer.getBlockBlobReference(sourceBlob);
    if (blobSource.exists()) {
        CloudBlockBlob blobTarget = blobContainer.getBlockBlobReference(targetBlob);
        SocketAccess.doPrivilegedVoidException(() -> {
            blobTarget.startCopy(blobSource);
            blobSource.delete();
        });
        logger.debug("moveBlob container [{}], sourceBlob [{}], targetBlob [{}] -> done", container, sourceBlob, targetBlob);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:AzureStorageServiceImpl.java

示例4: setUpStorageAccount

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) {
    try {
        CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
        // Create a blob service client
        CloudBlobClient blobClient = account.createCloudBlobClient();
        CloudBlobContainer container = blobClient.getContainerReference(containerName);
        container.createIfNotExists();
        BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
        // Include public access in the permissions object
        containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
        // Set the permissions on the container
        container.uploadPermissions(containerPermissions);
        return container;
    } catch (StorageException | URISyntaxException | InvalidKeyException e) {
        throw new RuntimeException(e);
    }

}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:19,代码来源:ManageLinuxWebAppStorageAccountConnection.java

示例5: getImageAsArray

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
public byte[] getImageAsArray(String imagefilename) {
	byte[] b = null;

	CloudBlobClient serviceClient = cloudStorageAccount.createCloudBlobClient();
	// Container name must be lower case.
	CloudBlobContainer container;
	try {
		container = serviceClient.getContainerReference(azureStorageProperties.getBlobContainer());
		CloudBlockBlob imgBlob = container.getBlockBlobReference(imagefilename);
		b = downloadImage(imgBlob);
	} catch (URISyntaxException | StorageException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	//return result
	return b;    	
}
 
开发者ID:Azure,项目名称:CityPower-Build-Sample,代码行数:18,代码来源:AzureImageStorageServiceImpl.java

示例6: primeRootContainer

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
private static CloudBlockBlob primeRootContainer(CloudBlobClient blobClient,
    String accountName, String blobName, int fileSize) throws Exception {

  // Create a container if it does not exist. The container name
  // must be lower case.
  CloudBlobContainer container = blobClient.getContainerReference("https://"
      + accountName + "/" + "$root");
  container.createIfNotExists();

  // Create a blob output stream.
  CloudBlockBlob blob = container.getBlockBlobReference(blobName);
  BlobOutputStream outputStream = blob.openOutputStream();

  outputStream.write(new byte[fileSize]);
  outputStream.close();

  // Return a reference to the block blob object.
  return blob;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:AzureBlobStorageTestAccount.java

示例7: getImageAsArray

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
public byte[] getImageAsArray(String imagefilename) {
  	byte[] b = null;
  	
      CloudBlobClient serviceClient = cloudStorageAccount.createCloudBlobClient();
      // Container name must be lower case.
      CloudBlobContainer container;
try {
	container = serviceClient.getContainerReference(azureStorageProperties.getBlobContainer());
       CloudBlockBlob imgBlob = container.getBlockBlobReference(imagefilename);
       b = downloadImage(imgBlob);
} catch (URISyntaxException | StorageException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
      //return result
      return b;    	
  }
 
开发者ID:Azure,项目名称:CityPower-Build-Sample,代码行数:18,代码来源:AzureImageStorageServiceImpl.java

示例8: storeImage

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
public String storeImage(String IncidentId, String fileName, String contentType, byte[] fileBuffer) {
      CloudBlobClient serviceClient = cloudStorageAccount.createCloudBlobClient();
      String imageUriString = null;
      // Container name must be lower case.
      CloudBlobContainer container;
try {
	container = serviceClient.getContainerReference(azureStorageProperties.getBlobContainer());
	container.createIfNotExists();
       // Set anonymous access on the container.
       BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
       containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
       container.uploadPermissions(containerPermissions);
       String incidentBlob = getIncidentBlobFilename(IncidentId,fileName);
       CloudBlockBlob imgBlob = container.getBlockBlobReference(incidentBlob);
       imgBlob.getProperties().setContentType(contentType);
       imgBlob.uploadFromByteArray(fileBuffer, 0, fileBuffer.length);
       imageUriString = incidentBlob;
} catch (URISyntaxException | StorageException | IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
      //return result
      return imageUriString;
  	
  }
 
开发者ID:Azure,项目名称:CityPower-Build-Sample,代码行数:26,代码来源:AzureImageStorageServiceImpl.java

示例9: getCloudBlobContainer

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
private CloudBlobContainer getCloudBlobContainer(String accountName, String accountKey, String containerName) {
  CloudBlobContainer container = null;

  if (StringUtils.isNotBlank(containerName)) {
    final String storageConnectionString = "DefaultEndpointsProtocol=https"
      + ";AccountName=" + accountName
      + ";AccountKey=" + accountKey;

    try {
      final CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
      CloudBlobClient serviceClient = account.createCloudBlobClient();

      container = serviceClient.getContainerReference(containerName);
      container.createIfNotExists();
    } catch (StorageException | URISyntaxException | InvalidKeyException e) {
      logger.error("Error connecting to container for account {} and container name {}", accountName, containerName, e);
    }
  }

  return container;
}
 
开发者ID:mesosphere,项目名称:dcos-cassandra-service,代码行数:22,代码来源:AzureStorageDriver.java

示例10: getContainer

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
/**
 * 获取容器
 * @param blobClient    Blob存储管理类  
 * @param containerName 容器名
 */
public static CloudBlobContainer getContainer(CloudBlobClient blobClient, String containerName) {
	try {
		//获取容器,如果容器不存在,则创建容器
		CloudBlobContainer container = blobClient.getContainerReference(containerName);
		container.createIfNotExists();

		BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
		containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
		container.uploadPermissions(containerPermissions);
		
		return container;
	} catch (Exception e) {
		DebugLog.e(TAG, "getContainer()", e);
		return null;
	}
}
 
开发者ID:leleliu008,项目名称:Newton_for_Android_AS,代码行数:22,代码来源:AzureStorage.java

示例11: createContainer

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
/**
 * Creates and returns a container for the sample application to use.
 *
 * @param blobClient CloudBlobClient object
 * @param containerName Name of the container to create
 * @return The newly created CloudBlobContainer object
 *
 * @throws StorageException
 * @throws RuntimeException
 * @throws IOException
 * @throws URISyntaxException
 * @throws IllegalArgumentException
 * @throws InvalidKeyException
 * @throws IllegalStateException
 */
private static CloudBlobContainer createContainer(CloudBlobClient blobClient, String containerName) throws StorageException, RuntimeException, IOException, InvalidKeyException, IllegalArgumentException, URISyntaxException, IllegalStateException {

    // Create a new container
    CloudBlobContainer container = blobClient.getContainerReference(containerName);
    try {
        if (container.createIfNotExists() == false) {
            throw new IllegalStateException(String.format("Container with name \"%s\" already exists.", containerName));
        }
    }
    catch (StorageException s) {
        if (s.getCause() instanceof java.net.ConnectException) {
            System.out.println("Caught connection exception from the client. If running with the default configuration please make sure you have started the storage emulator.");
        }
        throw s;
    }

    return container;
}
 
开发者ID:Azure-Samples,项目名称:storage-blob-java-getting-started,代码行数:34,代码来源:BlobBasics.java

示例12: init

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
@Override
public void init() throws Exception {
    super.init();

    // Validate configuration
    // Can throw IAEs
    this.validateConfiguration();

    try {
        StorageCredentials credentials = new StorageCredentialsAccountAndKey(storage_account_name, storage_access_key);
        CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, use_https);
        CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
        containerReference = blobClient.getContainerReference(container);
        boolean created = containerReference.createIfNotExists();

        if (created) {
            log.info("Created container named '%s'.", container);
        } else {
            log.debug("Using existing container named '%s'.", container);
        }

    } catch (Exception ex) {
        log.error("Error creating a storage client! Check your configuration.");
        throw ex;
    }
}
 
开发者ID:jgroups-extras,项目名称:jgroups-azure,代码行数:27,代码来源:AZURE_PING.java

示例13: testCreateContainer

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
@Before
public void testCreateContainer() {
    try {
        // Retrieve storage account from connection-string.
        CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);

        // Create the blob client.
        CloudBlobClient blobClient = storageAccount.createCloudBlobClient();

        // Get a reference to a container.
        // The container name must be lower case
        container = blobClient.getContainerReference(containerName);

        // Create the container if it does not exist.
        container.createIfNotExists();
    } catch (Exception e) {
        // Output the stack trace.
        e.printStackTrace();
    }
}
 
开发者ID:dzh,项目名称:jframe,代码行数:21,代码来源:TestBlobService.java

示例14: testDefaultProxy

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
@Test
public void testDefaultProxy() throws URISyntaxException, StorageException {
    CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference("container1");

    // Use a default proxy
    OperationContext.setDefaultProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.1.1.1", 8888)));

    // Turn off retries to make the failure happen faster
    BlobRequestOptions opt = new BlobRequestOptions();
    opt.setRetryPolicyFactory(new RetryNoRetry());

    // Unfortunately HttpURLConnection doesn't expose a getter and the usingProxy method it does have doesn't
    // work as one would expect and will always for us return false. So, we validate by making sure the request
    // fails when we set a bad proxy rather than check the proxy setting itself succeeding.
    try {
        container.exists(null, opt, null);
        fail("Bad proxy should throw an exception.");
    } catch (StorageException e) {
        if (e.getCause().getClass() != ConnectException.class &&
                e.getCause().getClass() != SocketTimeoutException.class &&
                e.getCause().getClass() != SocketException.class) {
            Assert.fail("Unepected exception for bad proxy");
        }
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:27,代码来源:GenericTests.java

示例15: testCloudStorageAccountClientUriVerify

import com.microsoft.azure.storage.blob.CloudBlobClient; //导入方法依赖的package包/类
@Test
public void testCloudStorageAccountClientUriVerify() throws URISyntaxException, StorageException {
    StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY);
    CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true);

    CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference("container1");
    assertEquals(cloudStorageAccount.getBlobEndpoint().toString() + "/container1", container.getUri().toString());

    CloudQueueClient queueClient = cloudStorageAccount.createCloudQueueClient();
    CloudQueue queue = queueClient.getQueueReference("queue1");
    assertEquals(cloudStorageAccount.getQueueEndpoint().toString() + "/queue1", queue.getUri().toString());

    CloudTableClient tableClient = cloudStorageAccount.createCloudTableClient();
    CloudTable table = tableClient.getTableReference("table1");
    assertEquals(cloudStorageAccount.getTableEndpoint().toString() + "/table1", table.getUri().toString());

    CloudFileClient fileClient = cloudStorageAccount.createCloudFileClient();
    CloudFileShare share = fileClient.getShareReference("share1");
    assertEquals(cloudStorageAccount.getFileEndpoint().toString() + "/share1", share.getUri().toString());
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:22,代码来源:StorageAccountTests.java


注:本文中的com.microsoft.azure.storage.blob.CloudBlobClient.getContainerReference方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。