@Override public void startCopyFromBlob(CloudBlobWrapper sourceBlob, BlobRequestOptions options, OperationContext opContext, boolean overwriteDestination) throws StorageException, URISyntaxException { AccessCondition dstAccessCondition = overwriteDestination ? null : AccessCondition.generateIfNotExistsCondition(); getBlob().startCopy(sourceBlob.getBlob().getQualifiedUri(), null, dstAccessCondition, options, opContext); }
@Override public void startCopyFromBlob(CloudBlobWrapper sourceBlob, BlobRequestOptions options, OperationContext opContext, boolean overwriteDestination) throws StorageException, URISyntaxException { AccessCondition dstAccessCondition = overwriteDestination ? null : AccessCondition.generateIfNotExistsCondition(); getBlob().startCopy(sourceBlob.getBlob().getQualifiedUri(), null, dstAccessCondition, options, opContext); }
private void uploadPageBlob(Exchange exchange) throws Exception { LOG.trace("Updating a page blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange); CloudPageBlob client = BlobServiceUtil.createPageBlobClient(getConfiguration()); configureCloudBlobForWrite(client); BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange); if (opts.getAccessCond() == null) { // Default: do not reset the blob content if the blob already exists opts.setAccessCond(AccessCondition.generateIfNotExistsCondition()); } Boolean pageBlobCreated = exchange.getIn().getHeader(BlobServiceConstants.PAGE_BLOCK_CREATED, Boolean.class); if (Boolean.TRUE != pageBlobCreated) { doCreatePageBlob(client, opts, exchange); } InputStream inputStream = getInputStreamFromExchange(exchange); doUpdatePageBlob(client, inputStream, opts, exchange); }
private void createAppendBlob(Exchange exchange) throws Exception { CloudAppendBlob client = BlobServiceUtil.createAppendBlobClient(getConfiguration()); BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange); if (opts.getAccessCond() == null) { // Default: do not reset the blob content if the blob already exists opts.setAccessCond(AccessCondition.generateIfNotExistsCondition()); } doCreateAppendBlob(client, opts, exchange); }
private void createPageBlob(Exchange exchange) throws Exception { CloudPageBlob client = BlobServiceUtil.createPageBlobClient(getConfiguration()); BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange); if (opts.getAccessCond() == null) { // Default: do not reset the blob content if the blob already exists opts.setAccessCond(AccessCondition.generateIfNotExistsCondition()); } doCreatePageBlob(client, opts, exchange); }
/** * 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); } } }
private void updateAppendBlob(Exchange exchange) throws Exception { CloudAppendBlob client = BlobServiceUtil.createAppendBlobClient(getConfiguration()); configureCloudBlobForWrite(client); BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange); if (opts.getAccessCond() == null) { // Default: do not reset the blob content if the blob already exists opts.setAccessCond(AccessCondition.generateIfNotExistsCondition()); } Boolean appendBlobCreated = exchange.getIn().getHeader(BlobServiceConstants.APPEND_BLOCK_CREATED, Boolean.class); if (Boolean.TRUE != appendBlobCreated) { doCreateAppendBlob(client, opts, exchange); } InputStream inputStream = getInputStreamFromExchange(exchange); try { client.appendBlock(inputStream, -1, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); } finally { closeInputStreamIfNeeded(inputStream); } }
condition = AccessCondition.generateIfNotExistsCondition(); try { blob.createOrReplace(condition, null, null);