/** * Creates an object of BlobUtils. It creates the container and page blob if they don't exist already. * @param client Client handle for access to Azure Storage account. * @param containerName Name of container inside which we want the blob to reside. * @param blobName Name of the blob to be managed. * @param length Length of the page blob. * @throws AzureException If an Azure storage service error occurred, or when the container name or blob name is invalid. */ public BlobUtils(AzureClient client, String containerName, String blobName, long length) { this.blobClient = client.getBlobClient(); try { this.container = blobClient.getContainerReference(containerName); container.createIfNotExists(); this.blob = container.getPageBlobReference(blobName); if (!blob.exists()) { blob.create(length, AccessCondition.generateIfNotExistsCondition(), null, null); } } catch (URISyntaxException e) { LOG.error("Container name: " + containerName + " or blob name: " + blobName + " invalid.", e); throw new AzureException(e); } catch (StorageException e) { int httpStatusCode = e.getHttpStatusCode(); if (httpStatusCode == HttpStatus.CONFLICT_409) { LOG.info("The blob you're trying to create exists already.", e); } else { LOG.error("Azure Storage Exception!", e); throw new AzureException(e); } } }
sasSnapshotBlob.exists(); CloudPageBlob copy = this.container.getPageBlobReference("copy");
private void testGetParent(String delimiter, CloudBlobContainer container) throws URISyntaxException, StorageException { CloudPageBlob blob = container.getPageBlobReference("Dir1" + delimiter + "Blob1"); blob.create(0); try { assertTrue(blob.exists()); assertEquals(blob.getName(), "Dir1" + delimiter + "Blob1"); CloudBlobDirectory parent = blob.getParent(); assertEquals("Dir1" + delimiter, parent.getPrefix()); } finally { blob.deleteIfExists(); } }
sasSnapshotBlob.exists(); CloudPageBlob copy = this.container.getPageBlobReference(BlobTestHelper.generateRandomBlobNameWithPrefix("copy"));
assertTrue(pageBlob.exists()); assertEquals(dir1.getContainer().getName(), pageBlob.getContainer().getName()); assertEquals(dir1.getServiceClient().getEndpoint().toString(), pageBlob.getServiceClient().getEndpoint()
CloudPageBlob sasBlob = (CloudPageBlob) sasClient.getContainerReference(container.getName()) .getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null); sasBlob.exists();