本文整理汇总了Java中com.microsoft.azure.storage.blob.CloudBlobContainer.exists方法的典型用法代码示例。如果您正苦于以下问题:Java CloudBlobContainer.exists方法的具体用法?Java CloudBlobContainer.exists怎么用?Java CloudBlobContainer.exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.microsoft.azure.storage.blob.CloudBlobContainer
的用法示例。
在下文中一共展示了CloudBlobContainer.exists方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupContainer
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
private CloudBlobContainer setupContainer(CloudBlobClient blobClient, String containerName) {
try {
CloudBlobContainer container = blobClient.getContainerReference(containerName);
if (!container.exists()) {
container.createIfNotExists();
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
container.uploadPermissions(containerPermissions);
}
return container;
} catch (Exception e) {
e.printStackTrace();
logger.error("Error setting up container: " + e.getMessage());
return null;
}
}
示例2: testDefaultProxy
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的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");
}
}
}
示例3: regularUpload
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
private boolean regularUpload(CloudBlobContainer container, String fileName, PluggableMessage pluggableMessage,
Map<String, String> customMetadata, long fileSize) throws UnableToProduceException {
boolean status = false;
CloudBlockBlob singleBlob;
String containerName = container.getName();
try {
if (container.exists()) {
log.info(LOGGER_KEY + "Container exists: " + containerName);
singleBlob = container.getBlockBlobReference(fileName);
log.info(LOGGER_KEY + "User metadata being applied ..." + customMetadata.size() + " key(s)");
singleBlob.setMetadata((HashMap<String, String>) customMetadata);
log.info(LOGGER_KEY + "Initiating blob upload with regular mode");
singleBlob.upload(FileUtils.openInputStream(pluggableMessage.getData().toFile()), fileSize);
if (singleBlob.exists())
log.info(LOGGER_KEY + "Azure Blob upload finished successfully.");
}
} catch (URISyntaxException urie) {
log.error(LOGGER_KEY + "Azure Resource URI constructed based on the containerName is invalid. "
+ urie.getMessage());
throw new UnableToProduceException(urie.getMessage(), urie);
} catch (StorageException se) {
log.error(LOGGER_KEY + "Azure Storage Service Error occurred. " + se.getMessage());
throw new UnableToProduceException(se.getMessage(), se);
} catch (IOException ioe) {
log.error(LOGGER_KEY + "Azure Storage I/O exception occurred. " + ioe.getMessage());
throw new UnableToProduceException(ioe.getMessage(), ioe);
} finally {
status = true;
}
return status;
}
示例4: blobExists
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Override
public boolean blobExists(String account, LocationMode mode, String container, String blob) throws URISyntaxException, StorageException {
// Container name must be lower case.
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
if (blobContainer.exists()) {
CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blob);
return SocketAccess.doPrivilegedException(azureBlob::exists);
}
return false;
}
示例5: deleteBlob
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Override
public void deleteBlob(String account, LocationMode mode, String container, String blob) throws URISyntaxException, StorageException {
logger.trace("delete blob for container [{}], blob [{}]", container, blob);
// Container name must be lower case.
CloudBlobClient client = this.getSelectedClient(account, mode);
CloudBlobContainer blobContainer = client.getContainerReference(container);
if (blobContainer.exists()) {
logger.trace("container [{}]: blob [{}] found. removing.", container, blob);
CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blob);
SocketAccess.doPrivilegedVoidException(azureBlob::delete);
}
}
示例6: deleteBlob
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public static void deleteBlob(final CloudStorageAccount storageAccount, final String containerName,
final String blobName) throws Exception {
final CloudBlobContainer blobContainer = getBlobContainer(storageAccount, containerName);
if (blobContainer.exists()) {
final CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobName);
blob.deleteIfExists();
}
}
示例7: validate
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Override
public void validate(ConfigProblemSetBuilder ps, AzsPersistentStore n) {
String connectionString = "DefaultEndpointsProtocol=https;AccountName=" + n.getStorageAccountName() + ";AccountKey=" + n.getStorageAccountKey();
try {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString);
CloudBlobContainer container = storageAccount.createCloudBlobClient().getContainerReference(n.getStorageContainerName());
container.exists();
} catch (Exception e) {
ps.addProblem(Problem.Severity.ERROR, "Failed to connect to the Azure storage account \"" + n.getStorageAccountName() + "\": " + e.getMessage());
return;
}
}
示例8: testProxy
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
public void testProxy() throws URISyntaxException, StorageException {
CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("container1");
// Use a request-level proxy
OperationContext opContext = new OperationContext();
opContext.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.1.1.1", 8888)));
// Turn of 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.
try {
container.exists(null, opt, opContext);
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");
}
}
}
示例9: testProxyOverridesDefault
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
public void testProxyOverridesDefault() throws URISyntaxException, StorageException {
CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("container1");
// Set 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) {
Assert.fail("Unepected exception for bad proxy");
}
}
// Override it with no proxy
OperationContext opContext = new OperationContext();
opContext.setProxy(Proxy.NO_PROXY);
// Should succeed as request-level proxy should override the bad default proxy
container.exists(null, null, opContext);
}
示例10: testUserAgentString
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
public void testUserAgentString() throws URISyntaxException, StorageException {
// Test with a blob request
CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("container1");
OperationContext sendingRequestEventContext = new OperationContext();
sendingRequestEventContext.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
assertEquals(
Constants.HeaderConstants.USER_AGENT_PREFIX
+ "/"
+ Constants.HeaderConstants.USER_AGENT_VERSION
+ " "
+ String.format(Utility.LOCALE_US, "(Android %s; %s; %s)",
android.os.Build.VERSION.RELEASE, android.os.Build.BRAND,
android.os.Build.MODEL), ((HttpURLConnection) eventArg.getConnectionObject())
.getRequestProperty(Constants.HeaderConstants.USER_AGENT));
}
});
container.exists(null, null, sendingRequestEventContext);
// Test with a queue request
CloudQueueClient queueClient = TestHelper.createCloudQueueClient();
CloudQueue queue = queueClient.getQueueReference("queue1");
queue.exists(null, sendingRequestEventContext);
// Test with a table request
CloudTableClient tableClient = TestHelper.createCloudTableClient();
CloudTable table = tableClient.getTableReference("table1");
table.exists(null, sendingRequestEventContext);
}
示例11: testNullRetryPolicy
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
public void testNullRetryPolicy() throws URISyntaxException, StorageException {
CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("container1");
blobClient.getDefaultRequestOptions().setRetryPolicyFactory(null);
container.exists();
}
示例12: createAnonymous
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public static AzureBlobStorageTestAccount createAnonymous(
final String blobName, final int fileSize) throws Exception {
NativeAzureFileSystem fs = null;
CloudBlobContainer container = null;
Configuration conf = createTestConfiguration(), noTestAccountConf = new Configuration();
// Set up a session with the cloud blob client to generate SAS and check the
// existence of a container and capture the container object.
CloudStorageAccount account = createTestAccount(conf);
if (account == null) {
return null;
}
CloudBlobClient blobClient = account.createCloudBlobClient();
// Capture the account URL and the account name.
String accountName = conf.get(TEST_ACCOUNT_NAME_PROPERTY_NAME);
// Generate a container name and create a shared access signature string for
// it.
//
String containerName = generateContainerName();
// Set up public container with the specified blob name.
primePublicContainer(blobClient, accountName, containerName, blobName,
fileSize);
// Capture the blob container object. It should exist after generating the
// shared access signature.
container = blobClient.getContainerReference(containerName);
if (null == container || !container.exists()) {
final String errMsg = String
.format("Container '%s' expected but not found while creating SAS account.");
throw new Exception(errMsg);
}
// Set the account URI.
URI accountUri = createAccountUri(accountName, containerName);
// Initialize the Native Azure file system with anonymous credentials.
fs = new NativeAzureFileSystem();
fs.initialize(accountUri, noTestAccountConf);
// Create test account initializing the appropriate member variables.
AzureBlobStorageTestAccount testAcct = new AzureBlobStorageTestAccount(fs,
account, container);
// Return to caller with test account.
return testAcct;
}
示例13: createRoot
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public static AzureBlobStorageTestAccount createRoot(final String blobName,
final int fileSize) throws Exception {
NativeAzureFileSystem fs = null;
CloudBlobContainer container = null;
Configuration conf = createTestConfiguration();
// Set up a session with the cloud blob client to generate SAS and check the
// existence of a container and capture the container object.
CloudStorageAccount account = createTestAccount(conf);
if (account == null) {
return null;
}
CloudBlobClient blobClient = account.createCloudBlobClient();
// Capture the account URL and the account name.
String accountName = conf.get(TEST_ACCOUNT_NAME_PROPERTY_NAME);
// Set up public container with the specified blob name.
CloudBlockBlob blobRoot = primeRootContainer(blobClient, accountName,
blobName, fileSize);
// Capture the blob container object. It should exist after generating the
// shared access signature.
container = blobClient.getContainerReference(AZURE_ROOT_CONTAINER);
if (null == container || !container.exists()) {
final String errMsg = String
.format("Container '%s' expected but not found while creating SAS account.");
throw new Exception(errMsg);
}
// Set the account URI without a container name.
URI accountUri = createAccountUri(accountName);
// Initialize the Native Azure file system with anonymous credentials.
fs = new NativeAzureFileSystem();
fs.initialize(accountUri, conf);
// Create test account initializing the appropriate member variables.
// Set the container value to null for the default root container.
//
AzureBlobStorageTestAccount testAcct = new AzureBlobStorageTestAccount(
fs, account, blobRoot);
// Return to caller with test account.
return testAcct;
}
示例14: containerExist
import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
/**
* @return true if the a container exist with the given name, false otherwise
*
*/
public boolean containerExist(final String containerName) throws StorageException, URISyntaxException, InvalidKeyException {
CloudBlobClient cloudBlobClient = connection.getCloudStorageAccount().createCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName);
return cloudBlobContainer.exists();
}