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


Java CloudBlobContainer.deleteIfExists方法代码示例

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


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

示例1: testRetryOn304

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
public void testRetryOn304() throws StorageException, IOException, URISyntaxException {
    OperationContext operationContext = new OperationContext();
    operationContext.getRetryingEventHandler().addListener(new StorageEvent<RetryingEvent>() {
        @Override
        public void eventOccurred(RetryingEvent eventArg) {
            fail("Request should not be retried.");
        }
    });

    CloudBlobContainer container = BlobTestHelper.getRandomContainerReference();
    try {
        container.create();
        CloudBlockBlob blockBlobRef = (CloudBlockBlob) BlobTestHelper.uploadNewBlob(container, BlobType.BLOCK_BLOB,
                "originalBlob", 1024, null);
        AccessCondition accessCondition = AccessCondition.generateIfNoneMatchCondition(blockBlobRef.getProperties().getEtag());
        blockBlobRef.download(new ByteArrayOutputStream(), accessCondition, null, operationContext);
        
        fail("Download should fail with a 304.");
    } catch (StorageException ex) {
        assertEquals("The condition specified using HTTP conditional header(s) is not met.", ex.getMessage());
    } finally {
        container.deleteIfExists();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:26,代码来源:SecondaryTests.java

示例2: deleteContainer

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
/**
 * This method will remove the container from Azure Storage.
 * @param containerName
 * @return boolean
 */
public static boolean deleteContainer(String containerName )
   {
  if (ProjectUtil.isStringNullOREmpty(containerName)) {
    ProjectLogger.log("Container name can't be null or empty");
    return false;
  }
  CloudBlobContainer container =
      AzureConnectionManager.getContainer(containerName, true);
  if (container == null) {
    ProjectLogger.log("Unable to get Azure contains object");
    return false;
  }
  try {
    boolean response = container.deleteIfExists();
    if(!response) {
      ProjectLogger.log("Container not found..");
    }else {
      ProjectLogger.log("Container is deleted===");
    }
    return true;
  } catch (Exception e) {
    ProjectLogger.log(e.getMessage(), e);
  }
  return false;
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:31,代码来源:AzureFileUtility.java

示例3: testCopyBlockBlobSas

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
@Category(SlowTests.class)
public void testCopyBlockBlobSas() throws Exception {
    // Create source on server.
    final CloudBlobContainer container = BlobTestHelper.getRandomContainerReference();
    try {
        container.create();
        final CloudBlockBlob source = container.getBlockBlobReference("source");

        source.getMetadata().put("Test", "value");
        final String data = "String data";
        source.uploadText(data, Constants.UTF8_CHARSET, null, null, null);

        final CloudFile destination = doCloudBlobCopy(source, data.length());

        final String copyData = destination.downloadText(Constants.UTF8_CHARSET, null, null, null);
        assertEquals(data, copyData);
    }
    finally {
        container.deleteIfExists();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:23,代码来源:CloudFileTests.java

示例4: testCopyPageBlobSas

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
@Category(SlowTests.class)
public void testCopyPageBlobSas() throws Exception {
    // Create source on server.
    final CloudBlobContainer container = BlobTestHelper.getRandomContainerReference();
    try {
        container.create();
        final CloudPageBlob source = container.getPageBlobReference("source");

        source.getMetadata().put("Test", "value");
        final int length = 512;
        final ByteArrayInputStream data = BlobTestHelper.getRandomDataStream(length);
        source.upload(data, length);

        final CloudFile destination = doCloudBlobCopy(source, length);

        final ByteArrayOutputStream copyData = new ByteArrayOutputStream();
        destination.download(copyData);
        BlobTestHelper.assertStreamsAreEqual(data, new ByteArrayInputStream(copyData.toByteArray()));
    }
    finally {
        container.deleteIfExists();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:25,代码来源:CloudFileTests.java

示例5: EnablePerRequestLogging

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public static void EnablePerRequestLogging(CloudBlobContainer container) throws StorageException, URISyntaxException, IOException {
    System.out.println("Enable logging per selected requests");

    // Set logging to false by default and pass in an operation context to log only specific APIs
    OperationContext.setLoggingEnabledByDefault(false);

    // Upload a blob passing in the operation context
    // Get a reference to a blob in the container
    // This operation will not be logged since it does not make a service request.
    CloudBlockBlob blob = container.getBlockBlobReference("blob");

    OperationContext operationContext = new OperationContext();
    operationContext.setLoggingEnabled(true);

    // Upload text to the blob passing in the operation context so the request is logged.
    // This operation contacts the Azure Storage Service and will be logged
    // since it is passing in an operation context that enables logging.
    blob.uploadText("Hello, World", null, null, null, operationContext);

    // Delete the container if it exists.
    // This operation will not be logged since logging has been disabled
    // by default and no operation context is being passed in.
    container.deleteIfExists();
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:25,代码来源:ClientLoggingBasics.java

示例6: deleteContainerIfExist

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
/**
 * This method delete the container if exist
 * 
 */
public boolean deleteContainerIfExist(final String containerName)
        throws StorageException, URISyntaxException, InvalidKeyException {
    CloudBlobClient cloudBlobClient = connection.getCloudStorageAccount().createCloudBlobClient();
    CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName);
    return cloudBlobContainer.deleteIfExists();
}
 
开发者ID:Talend,项目名称:components,代码行数:11,代码来源:AzureStorageBlobService.java

示例7: testExecutionEngineErrorHandling

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
/**
 * Make sure that if a request throws an error when it is being built that the request is not sent.
 *
 * @throws URISyntaxException
 * @throws StorageException
 */
@Test
public void testExecutionEngineErrorHandling() throws URISyntaxException, StorageException {
    CloudBlobContainer container = BlobTestHelper.getRandomContainerReference();
    try {
        final ArrayList<Boolean> callList = new ArrayList<Boolean>();

        OperationContext opContext = new OperationContext();
        opContext.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {
            // insert a metadata element with an empty value
            @Override
            public void eventOccurred(SendingRequestEvent eventArg) {
                callList.add(true);
            }
        });

        container.getMetadata().put("key", " "); // invalid value
        try {
            container.uploadMetadata(null, null, opContext);
            fail(SR.METADATA_KEY_INVALID);
        } catch (StorageException e) {
            // make sure a request was not sent
            assertEquals(0, callList.size());

            assertEquals(SR.METADATA_VALUE_INVALID, e.getMessage());
        }
    } finally {
        container.deleteIfExists();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:36,代码来源:GenericTests.java

示例8: deleteContainerInStorage

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public void deleteContainerInStorage(String resourceGroup, String storageName, String containerName) {
    LOGGER.debug("delete container: RG={}, storageName={}, containerName={}", resourceGroup, storageName, containerName);
    CloudBlobContainer container = getBlobContainer(resourceGroup, storageName, containerName);
    try {
        boolean existed = container.deleteIfExists();
        LOGGER.info("is container existed: " + existed);
    } catch (StorageException e) {
        throw new CloudConnectorException("can't delete container in storage, storage service error occurred", e);
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:11,代码来源:AzureClient.java

示例9: main

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
/**
 * Executes the sample.
 *
 * @param args
 *            No input args are expected from users.
 * @throws URISyntaxException
 * @throws InvalidKeyException
 */
public static void main(String[] args) throws InvalidKeyException, URISyntaxException, StorageException {
    // Logs will be written to standard out by default and can be redirected to a file
    System.out.println("The Azure storage client sample to enable logging has started.");

    // Setup the cloud storage account.
    CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);

    // Create a blob service client
    CloudBlobClient blobClient = account.createCloudBlobClient();

    // Get a reference to a container
    // This operation will not be logged since it does not make a service request.
    // Append a random UUID to the end of the container name so that
    // this sample can be run more than once in quick succession.
    CloudBlobContainer container = blobClient.getContainerReference("basicloggingcontainer"
            + UUID.randomUUID().toString().replace("-", ""));

    try {
        EnableGlobalLogging(container);

        EnablePerRequestLogging(container);
    }
    catch (Throwable t) {
        printException(t);
        container.deleteIfExists();
    }

    System.out.println("The Azure storage client sample to enable logging has completed.");
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:38,代码来源:ClientLoggingBasics.java

示例10: testReadTimeoutIssue

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public void testReadTimeoutIssue() throws URISyntaxException, StorageException, IOException {
    // part 1
    byte[] buffer = BlobTestHelper.getRandomBuffer(1 * 1024 * 1024);

    // set the maximum execution time
    BlobRequestOptions options = new BlobRequestOptions();
    options.setMaximumExecutionTimeInMs(5000);

    CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference(generateRandomContainerName());

    String blobName = "testBlob";
    final CloudBlockBlob blockBlobRef = container.getBlockBlobReference(blobName);
    blockBlobRef.setStreamWriteSizeInBytes(1 * 1024 * 1024);

    ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer);
    BlobOutputStream blobOutputStream = null;

    try {
        container.createIfNotExists();
        blobOutputStream = blockBlobRef.openOutputStream(null, options, null);
        try {
            blobOutputStream.write(inputStream, buffer.length);
        } finally {
            blobOutputStream.close();
        }
        assertTrue(blockBlobRef.exists());
    } finally {
        inputStream.close();
        container.deleteIfExists();
    }

    // part 2
    int length2 = 10 * 1024 * 1024;
    byte[] uploadBuffer2 = BlobTestHelper.getRandomBuffer(length2);

    CloudBlobClient blobClient2 = TestHelper.createCloudBlobClient();
    CloudBlobContainer container2 = blobClient2.getContainerReference(generateRandomContainerName());

    String blobName2 = "testBlob";
    final CloudBlockBlob blockBlobRef2 = container2.getBlockBlobReference(blobName2);

    ByteArrayInputStream inputStream2 = new ByteArrayInputStream(uploadBuffer2);

    try {
        container2.createIfNotExists();

        blockBlobRef2.upload(inputStream2, length2);
    } finally {
        inputStream2.close();
        container2.deleteIfExists();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:54,代码来源:GenericTests.java

示例11: testMaximumExecutionTimeBlobByteArray

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
@Category({ DevFabricTests.class, DevStoreTests.class, SlowTests.class })
public void testMaximumExecutionTimeBlobByteArray() throws URISyntaxException, StorageException, IOException {
    int length = 10 * 1024 * 1024;
    byte[] uploadBuffer = BlobTestHelper.getRandomBuffer(length);
    byte[] downloadBuffer = new byte[length];

    // set a delay in sending request
    OperationContext opContext = new OperationContext();
    setDelay(opContext, 2500);

    // set the maximum execution time
    BlobRequestOptions options = new BlobRequestOptions();
    options.setMaximumExecutionTimeInMs(2000);

    CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference(generateRandomName("container"));

    String blobName = "testBlob";
    final CloudBlockBlob blockBlobRef = container.getBlockBlobReference(blobName);

    ByteArrayInputStream inputStream = new ByteArrayInputStream(uploadBuffer);

    try {
        container.createIfNotExists();

        blockBlobRef.upload(inputStream, length);
        assertTrue(blockBlobRef.exists());

        try {
            blockBlobRef.downloadToByteArray(downloadBuffer, 0, null, options, opContext);
            fail("Maximum execution time was reached but request did not fail.");
        }
        catch (StorageException e) {
            assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getCause().getMessage());
        }
    }
    finally {
        inputStream.close();
        container.deleteIfExists();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:43,代码来源:MaximumExecutionTimeTests.java

示例12: main

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
public static void main(String[] args) throws InvalidKeyException,
        URISyntaxException, StorageException, NoSuchAlgorithmException,
        IOException {
    Utility.printSampleStartInfo("BlobBasicsEncryption");

    // Retrieve storage account information from connection string
    // How to create a storage connection string -
    // https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/
    CloudStorageAccount account = CloudStorageAccount
            .parse(Utility.storageConnectionString);
    CloudBlobClient blobClient = account.createCloudBlobClient();

    // Get a reference to a container
    // The container name must be lower case
    // Append a random UUID to the end of the container name so that
    // this sample can be run more than once in quick succession.
    CloudBlobContainer container = blobClient
            .getContainerReference("blobencryptioncontainer"
                    + UUID.randomUUID().toString().replace("-", ""));

    try {
        // Create the container if it does not exist
        container.createIfNotExists();

        int size = 5 * 1024 * 1024;
        byte[] buffer = new byte[size];

        Random rand = new Random();
        rand.nextBytes(buffer);

        CloudBlockBlob blob = container.getBlockBlobReference("blockBlob");

        // Create the IKey used for encryption.
        final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(1024);
        final KeyPair wrapKey = keyGen.generateKeyPair();
        RsaKey key = new RsaKey("rsaKey1", wrapKey);

        // Create the encryption policy to be used for upload.
        BlobEncryptionPolicy uploadPolicy = new BlobEncryptionPolicy(key,
                null);

        // Set the encryption policy on the request options.
        BlobRequestOptions uploadOptions = new BlobRequestOptions();
        uploadOptions.setEncryptionPolicy(uploadPolicy);

        System.out.println("Uploading the encrypted blob.");

        // Upload the encrypted contents to the blob.
        ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer);
        blob.upload(inputStream, size, null, uploadOptions, null);

        // Download the encrypted blob.
        // For downloads, a resolver can be set up that will help pick the
        // key based on the key id.
        // Create the encryption policy to be used for download.
        LocalResolver resolver = new LocalResolver();
        resolver.add(key);
        BlobEncryptionPolicy downloadPolicy = new BlobEncryptionPolicy(
                null, resolver);

        // Set the decryption policy on the request options.
        BlobRequestOptions downloadOptions = new BlobRequestOptions();
        downloadOptions.setEncryptionPolicy(downloadPolicy);

        System.out.println("Downloading the encrypted blob.");

        // Download and decrypt the encrypted contents from the blob.
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        blob.download(outputStream, null, downloadOptions, null);
    } finally {
        // Delete the container
        container.deleteIfExists();
        Utility.printSampleCompleteInfo("BlobBasicsEncryption");
    }
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:77,代码来源:BlobGettingStarted.java

示例13: testStringToSign

import com.microsoft.azure.storage.blob.CloudBlobContainer; //导入方法依赖的package包/类
@Test
public synchronized void testStringToSign()
        throws IOException, InvalidKeyException, StorageException, URISyntaxException {
    
    OperationContext.setLoggingEnabledByDefault(true);
    final CloudBlobContainer cont = BlobTestHelper.getRandomContainerReference();
    
    try {
        cont.create();
        final CloudBlob blob = BlobTestHelper.uploadNewBlob(cont, BlobType.BLOCK_BLOB, "", 0, null);
        
        // Test logging for SAS access
        baos.reset();
        blob.generateSharedAccessSignature(null, null);
        baos.flush();

        String log = baos.toString();
        String[] logEntries = log.split("[\\r\\n]+");

        assertEquals(1, logEntries.length);
        
        // example log entry: TRACE ROOT - {0b902691-1a8e-41da-ab60-5b912df186a6}: {Test string}
        String[] segment = logEntries[0].split("\\{");
        assertEquals(3, segment.length);
        assertTrue(segment[1].startsWith("*"));
        assertTrue(segment[2].startsWith(String.format(LogConstants.SIGNING, Constants.EMPTY_STRING)));
        baos.reset();

        // Test logging for Shared Key access
        OperationContext ctx = new OperationContext();
        blob.downloadAttributes(null, null, ctx);
        
        baos.flush();
        log = baos.toString();
        logEntries = log.split("[\\r\\n]+");
        assertNotEquals(0, logEntries.length);
        
        // Select correct log entry
        for (int n = 0; n < logEntries.length; n++) {
            if (logEntries[n].startsWith(LoggerTests.TRACE)) {
                segment = logEntries[n].split("\\{");
                assertEquals(3, segment.length);
                assertTrue(segment[1].startsWith(ctx.getClientRequestID()));
                assertTrue(segment[2].startsWith(String.format(LogConstants.SIGNING, Constants.EMPTY_STRING)));
                return;
            }
        }
        
        // If this line is reached then the log entry was not found
        fail();
    }
    finally {
        cont.deleteIfExists();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:56,代码来源:LoggerTests.java


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