Package com.azure.storage.blob.batch
Class BlobBatchClient
- java.lang.Object
-
- com.azure.storage.blob.batch.BlobBatchClient
-
public final class BlobBatchClient extends Object
This class provides a client that contains all operations that apply to Azure Storage Blob batching.This client offers the ability to delete and set access tier on multiple blobs at once and to submit a
BlobBatch.- See Also:
BlobBatch,BlobBatchClientBuilder
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.azure.core.http.rest.PagedIterable<com.azure.core.http.rest.Response<Void>>deleteBlobs(List<String> blobUrls, DeleteSnapshotsOptionType deleteOptions)Delete multiple blobs in a single request to the service.com.azure.core.http.rest.PagedIterable<com.azure.core.http.rest.Response<Void>>deleteBlobs(List<String> blobUrls, DeleteSnapshotsOptionType deleteOptions, Duration timeout, com.azure.core.util.Context context)Delete multiple blobs in a single request to the service.BlobBatchgetBlobBatch()Gets aBlobBatchused to configure a batching operation to send to Azure Storage blobs.com.azure.core.http.rest.PagedIterable<com.azure.core.http.rest.Response<Void>>setBlobsAccessTier(List<String> blobUrls, AccessTier accessTier)Set access tier on multiple blobs in a single request to the service.com.azure.core.http.rest.PagedIterable<com.azure.core.http.rest.Response<Void>>setBlobsAccessTier(List<String> blobUrls, AccessTier accessTier, Duration timeout, com.azure.core.util.Context context)Set access tier on multiple blobs in a single request to the service.voidsubmitBatch(BlobBatch batch)Submits a batch operation.com.azure.core.http.rest.Response<Void>submitBatchWithResponse(BlobBatch batch, boolean throwOnAnyFailure, Duration timeout, com.azure.core.util.Context context)Submits a batch operation.
-
-
-
Method Detail
-
getBlobBatch
public BlobBatch getBlobBatch()
Gets aBlobBatchused to configure a batching operation to send to Azure Storage blobs.- Returns:
- a new
BlobBatchinstance.
-
submitBatch
public void submitBatch(BlobBatch batch)
Submits a batch operation.If any request in a batch fails this will throw a
BlobStorageException.Code samples
BlobBatch batch = batchClient.getBlobBatch(); Response<Void> deleteResponse1 = batch.deleteBlob("container", "blob1"); Response<Void> deleteResponse2 = batch.deleteBlob("container", "blob2", DeleteSnapshotsOptionType.INCLUDE, new BlobRequestConditions().setLeaseId("leaseId")); try { batchClient.submitBatch(batch); System.out.println("Batch submission completed successfully."); System.out.printf("Delete operation 1 completed with status code: %d%n", deleteResponse1.getStatusCode()); System.out.printf("Delete operation 2 completed with status code: %d%n", deleteResponse2.getStatusCode()); } catch (BlobStorageException error) { System.err.printf("Batch submission failed. Error message: %s%n", error.getMessage()); }- Parameters:
batch- Batch to submit.- Throws:
BlobStorageException- If the batch request is malformed.BlobBatchStorageException- If any request in theBlobBatchfailed.
-
submitBatchWithResponse
public com.azure.core.http.rest.Response<Void> submitBatchWithResponse(BlobBatch batch, boolean throwOnAnyFailure, Duration timeout, com.azure.core.util.Context context)
Submits a batch operation.If
throwOnAnyFailureistrueaBlobStorageExceptionwill be thrown if any request fails.Code samples
BlobBatch batch = batchClient.getBlobBatch(); Response<Void> deleteResponse1 = batch.deleteBlob("container", "blob1"); Response<Void> deleteResponse2 = batch.deleteBlob("container", "blob2", DeleteSnapshotsOptionType.INCLUDE, new BlobRequestConditions().setLeaseId("leaseId")); try { System.out.printf("Batch submission completed with status code: %d%n", batchClient.submitBatchWithResponse(batch, true, timeout, Context.NONE).getStatusCode()); System.out.printf("Delete operation 1 completed with status code: %d%n", deleteResponse1.getStatusCode()); System.out.printf("Delete operation 2 completed with status code: %d%n", deleteResponse2.getStatusCode()); } catch (BlobStorageException error) { System.err.printf("Batch submission failed. Error message: %s%n", error.getMessage()); }- Parameters:
batch- Batch to submit.throwOnAnyFailure- Flag to indicate if an exception should be thrown if any request in the batch fails.timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- A response only containing header and status code information, used to indicate that the batch operation has completed.
- Throws:
RuntimeException- If thetimeoutduration completes before a response is returned.BlobStorageException- If the batch request is malformed.BlobBatchStorageException- IfthrowOnAnyFailureistrueand any request in theBlobBatchfailed.
-
deleteBlobs
public com.azure.core.http.rest.PagedIterable<com.azure.core.http.rest.Response<Void>> deleteBlobs(List<String> blobUrls, DeleteSnapshotsOptionType deleteOptions)
Delete multiple blobs in a single request to the service.Code samples
List<String> blobUrls = new ArrayList<>(); blobUrls.add(blobClient1.getBlobUrl()); blobUrls.add(blobClient2.getBlobUrl()); blobUrls.add(blobClient3.getBlobUrl()); try { batchClient.deleteBlobs(blobUrls, DeleteSnapshotsOptionType.INCLUDE).forEach(response -> System.out.printf("Deleting blob with URL %s completed with status code %d%n", response.getRequest().getUrl(), response.getStatusCode())); } catch (Throwable error) { System.err.printf("Deleting blob failed with exception: %s%n", error.getMessage()); }- Parameters:
blobUrls- Urls of the blobs to delete. Blob names must be encoded to UTF-8.deleteOptions- The deletion option for all blobs.- Returns:
- The status of each delete operation.
- Throws:
BlobStorageException- If the batch request is malformed.BlobBatchStorageException- If any of the delete operations fail.
-
deleteBlobs
public com.azure.core.http.rest.PagedIterable<com.azure.core.http.rest.Response<Void>> deleteBlobs(List<String> blobUrls, DeleteSnapshotsOptionType deleteOptions, Duration timeout, com.azure.core.util.Context context)
Delete multiple blobs in a single request to the service.Code samples
List<String> blobUrls = new ArrayList<>(); blobUrls.add(blobClient1.getBlobUrl()); blobUrls.add(blobClient2.getBlobUrl()); blobUrls.add(blobClient3.getBlobUrl()); try { batchClient.deleteBlobs(blobUrls, DeleteSnapshotsOptionType.INCLUDE, timeout, Context.NONE) .forEach(response -> System.out.printf("Deleting blob with URL %s completed with status code %d%n", response.getRequest().getUrl(), response.getStatusCode())); } catch (Throwable error) { System.err.printf("Deleting blob failed with exception: %s%n", error.getMessage()); }- Parameters:
blobUrls- Urls of the blobs to delete. Blob names must be encoded to UTF-8.deleteOptions- The deletion option for all blobs.timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The status of each delete operation.
- Throws:
RuntimeException- If thetimeoutduration completes before a response is returned.BlobStorageException- If the batch request is malformed.BlobBatchStorageException- If any of the delete operations fail.
-
setBlobsAccessTier
public com.azure.core.http.rest.PagedIterable<com.azure.core.http.rest.Response<Void>> setBlobsAccessTier(List<String> blobUrls, AccessTier accessTier)
Set access tier on multiple blobs in a single request to the service.Code samples
List<String> blobUrls = new ArrayList<>(); blobUrls.add(blobClient1.getBlobUrl()); blobUrls.add(blobClient2.getBlobUrl()); blobUrls.add(blobClient3.getBlobUrl()); try { batchClient.setBlobsAccessTier(blobUrls, AccessTier.HOT).forEach(response -> System.out.printf("Setting blob access tier with URL %s completed with status code %d%n", response.getRequest().getUrl(), response.getStatusCode())); } catch (Throwable error) { System.err.printf("Setting blob access tier failed with exception: %s%n", error.getMessage()); }- Parameters:
blobUrls- Urls of the blobs to set their access tier. Blob names must be encoded to UTF-8.accessTier-AccessTierto set on each blob.- Returns:
- The status of each set tier operation.
- Throws:
BlobStorageException- If the batch request is malformed.BlobBatchStorageException- If any of the set tier operations fail.
-
setBlobsAccessTier
public com.azure.core.http.rest.PagedIterable<com.azure.core.http.rest.Response<Void>> setBlobsAccessTier(List<String> blobUrls, AccessTier accessTier, Duration timeout, com.azure.core.util.Context context)
Set access tier on multiple blobs in a single request to the service.Code samples
List<String> blobUrls = new ArrayList<>(); blobUrls.add(blobClient1.getBlobUrl()); blobUrls.add(blobClient2.getBlobUrl()); blobUrls.add(blobClient3.getBlobUrl()); try { batchClient.setBlobsAccessTier(blobUrls, AccessTier.HOT, timeout, Context.NONE).forEach(response -> System.out.printf("Setting blob access tier with URL %s completed with status code %d%n", response.getRequest().getUrl(), response.getStatusCode())); } catch (Throwable error) { System.err.printf("Setting blob access tier failed with exception: %s%n", error.getMessage()); }- Parameters:
blobUrls- Urls of the blobs to set their access tier. Blob names must be encoded to UTF-8.accessTier-AccessTierto set on each blob.timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- Additional context that is passed through the Http pipeline during the service call.- Returns:
- The status of each set tier operation.
- Throws:
RuntimeException- If thetimeoutduration completes before a response is returned.BlobStorageException- If the batch request is malformed.BlobBatchStorageException- If any of the set tier operations fail.
-
-