From d389bd054cd299760bbc9d5cb31d73b9791ed97b Mon Sep 17 00:00:00 2001 From: "Melanie Ma (MSFT)" <64007802+Melanie-Ma@users.noreply.github.com> Date: Fri, 14 May 2021 01:03:42 +0800 Subject: [PATCH] fix the issue 18809 (#20773) --- ...obBatchAsyncClientJavaDocCodeSnippets.java | 29 ++++++------ .../BlobBatchClientJavaDocCodeSnippets.java | 46 ++++++++++--------- .../storage/blob/batch/ReadmeSamples.java | 10 ++-- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/BlobBatchAsyncClientJavaDocCodeSnippets.java b/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/BlobBatchAsyncClientJavaDocCodeSnippets.java index bd4ccc3212913..9f533fde7235c 100644 --- a/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/BlobBatchAsyncClientJavaDocCodeSnippets.java +++ b/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/BlobBatchAsyncClientJavaDocCodeSnippets.java @@ -6,7 +6,8 @@ import com.azure.core.http.rest.Response; import com.azure.core.util.Configuration; import com.azure.storage.blob.BlobClient; -import com.azure.storage.blob.BlobClientBuilder; +import com.azure.storage.blob.BlobContainerClient; +import com.azure.storage.blob.BlobServiceClient; import com.azure.storage.blob.BlobServiceClientBuilder; import com.azure.storage.blob.models.AccessTier; import com.azure.storage.blob.models.BlobRequestConditions; @@ -22,10 +23,12 @@ public class BlobBatchAsyncClientJavaDocCodeSnippets { private static final String ENDPOINT = Configuration.getGlobalConfiguration().get("PRIMARY_STORAGE_BLOB_ENDPOINT"); private static final String SASTOKEN = Configuration.getGlobalConfiguration().get("SAS_TOKEN"); - private BlobBatchAsyncClient batchAsyncClient = new BlobBatchClientBuilder(new BlobServiceClientBuilder() - .encryptionScope(ENDPOINT) - .sasToken(SASTOKEN).buildClient()) - .buildAsyncClient(); + private BlobServiceClient blobServiceClient = new BlobServiceClientBuilder() + .endpoint(ENDPOINT) + .sasToken(SASTOKEN) + .buildClient(); + + private BlobBatchAsyncClient batchAsyncClient = new BlobBatchClientBuilder(blobServiceClient).buildAsyncClient(); /** * Code snippet for {@link BlobBatchAsyncClient#submitBatch(BlobBatch)} @@ -69,10 +72,10 @@ public void submitBatchWithResponse() { * Code snippet for {@link BlobBatchAsyncClient#deleteBlobs(List, DeleteSnapshotsOptionType)} */ public void deleteBlobs() { - BlobClientBuilder blobClientBuilder = new BlobClientBuilder(); - BlobClient blobClient1 = blobClientBuilder.buildClient(); - BlobClient blobClient2 = blobClientBuilder.buildClient(); - BlobClient blobClient3 = blobClientBuilder.buildClient(); + BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(""); + BlobClient blobClient1 = containerClient.getBlobClient(""); + BlobClient blobClient2 = containerClient.getBlobClient(""); + BlobClient blobClient3 = containerClient.getBlobClient(""); // BEGIN: com.azure.storage.blob.batch.BlobBatchAsyncClient.deleteBlobs#List-DeleteSnapshotsOptionType List blobUrls = new ArrayList<>(); @@ -91,10 +94,10 @@ public void deleteBlobs() { * Code snippet for {@link BlobBatchAsyncClient#setBlobsAccessTier(List, AccessTier)} */ public void setBlobsAccessTier() { - BlobClientBuilder blobClientBuilder = new BlobClientBuilder(); - BlobClient blobClient1 = blobClientBuilder.buildClient(); - BlobClient blobClient2 = blobClientBuilder.buildClient(); - BlobClient blobClient3 = blobClientBuilder.buildClient(); + BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(""); + BlobClient blobClient1 = containerClient.getBlobClient(""); + BlobClient blobClient2 = containerClient.getBlobClient(""); + BlobClient blobClient3 = containerClient.getBlobClient(""); // BEGIN: com.azure.storage.blob.batch.BlobBatchAsyncClient.setBlobsAccessTier#List-AccessTier List blobUrls = new ArrayList<>(); diff --git a/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/BlobBatchClientJavaDocCodeSnippets.java b/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/BlobBatchClientJavaDocCodeSnippets.java index 4783010a0693f..8605cde380002 100644 --- a/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/BlobBatchClientJavaDocCodeSnippets.java +++ b/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/BlobBatchClientJavaDocCodeSnippets.java @@ -7,7 +7,8 @@ import com.azure.core.util.Configuration; import com.azure.core.util.Context; import com.azure.storage.blob.BlobClient; -import com.azure.storage.blob.BlobClientBuilder; +import com.azure.storage.blob.BlobContainerClient; +import com.azure.storage.blob.BlobServiceClient; import com.azure.storage.blob.BlobServiceClientBuilder; import com.azure.storage.blob.models.AccessTier; import com.azure.storage.blob.models.BlobRequestConditions; @@ -25,10 +26,13 @@ public class BlobBatchClientJavaDocCodeSnippets { private static final String ENDPOINT = Configuration.getGlobalConfiguration().get("PRIMARY_STORAGE_BLOB_ENDPOINT"); private static final String SASTOKEN = Configuration.getGlobalConfiguration().get("SAS_TOKEN"); - private BlobBatchClient batchClient = new BlobBatchClientBuilder(new BlobServiceClientBuilder() - .endpoint(ENDPOINT) - .sasToken(SASTOKEN).buildClient()) - .buildClient(); + private BlobServiceClient blobServiceClient = new BlobServiceClientBuilder() + .endpoint(ENDPOINT) + .sasToken(SASTOKEN) + .buildClient(); + + private BlobBatchClient batchClient = new BlobBatchClientBuilder(blobServiceClient).buildClient(); + private Duration timeout = Duration.ofSeconds(30); /** @@ -79,10 +83,10 @@ public void submitBatchWithResponse() { * Code snippet for {@link BlobBatchClient#deleteBlobs(List, DeleteSnapshotsOptionType)} */ public void deleteBlobs() { - BlobClientBuilder blobClientBuilder = new BlobClientBuilder(); - BlobClient blobClient1 = blobClientBuilder.buildClient(); - BlobClient blobClient2 = blobClientBuilder.buildClient(); - BlobClient blobClient3 = blobClientBuilder.buildClient(); + BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(""); + BlobClient blobClient1 = containerClient.getBlobClient(""); + BlobClient blobClient2 = containerClient.getBlobClient(""); + BlobClient blobClient3 = containerClient.getBlobClient(""); // BEGIN: com.azure.storage.blob.batch.BlobBatchClient.deleteBlobs#List-DeleteSnapshotsOptionType List blobUrls = new ArrayList<>(); @@ -104,10 +108,10 @@ public void deleteBlobs() { * Code snippet for {@link BlobBatchClient#deleteBlobs(List, DeleteSnapshotsOptionType, Duration, Context)} */ public void deleteBlobsWithTimeoutAndContext() { - BlobClientBuilder blobClientBuilder = new BlobClientBuilder(); - BlobClient blobClient1 = blobClientBuilder.buildClient(); - BlobClient blobClient2 = blobClientBuilder.buildClient(); - BlobClient blobClient3 = blobClientBuilder.buildClient(); + BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(""); + BlobClient blobClient1 = containerClient.getBlobClient(""); + BlobClient blobClient2 = containerClient.getBlobClient(""); + BlobClient blobClient3 = containerClient.getBlobClient(""); // BEGIN: com.azure.storage.blob.batch.BlobBatchClient.deleteBlobs#List-DeleteSnapshotsOptionType-Duration-Context List blobUrls = new ArrayList<>(); @@ -129,10 +133,10 @@ public void deleteBlobsWithTimeoutAndContext() { * Code snippet for {@link BlobBatchClient#setBlobsAccessTier(List, AccessTier)} */ public void setBlobsAccessTier() { - BlobClientBuilder blobClientBuilder = new BlobClientBuilder(); - BlobClient blobClient1 = blobClientBuilder.buildClient(); - BlobClient blobClient2 = blobClientBuilder.buildClient(); - BlobClient blobClient3 = blobClientBuilder.buildClient(); + BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(""); + BlobClient blobClient1 = containerClient.getBlobClient(""); + BlobClient blobClient2 = containerClient.getBlobClient(""); + BlobClient blobClient3 = containerClient.getBlobClient(""); // BEGIN: com.azure.storage.blob.batch.BlobBatchClient.setBlobsAccessTier#List-AccessTier List blobUrls = new ArrayList<>(); @@ -154,10 +158,10 @@ public void setBlobsAccessTier() { * Code snippet for {@link BlobBatchClient#setBlobsAccessTier(List, AccessTier, Duration, Context)} */ public void setBlobsAccessTierWithTimeoutAndContext() { - BlobClientBuilder blobClientBuilder = new BlobClientBuilder(); - BlobClient blobClient1 = blobClientBuilder.buildClient(); - BlobClient blobClient2 = blobClientBuilder.buildClient(); - BlobClient blobClient3 = blobClientBuilder.buildClient(); + BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(""); + BlobClient blobClient1 = containerClient.getBlobClient(""); + BlobClient blobClient2 = containerClient.getBlobClient(""); + BlobClient blobClient3 = containerClient.getBlobClient(""); // BEGIN: com.azure.storage.blob.batch.BlobBatchClient.setBlobsAccessTier#List-AccessTier-Duration-Context List blobUrls = new ArrayList<>(); diff --git a/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/ReadmeSamples.java b/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/ReadmeSamples.java index dcb4dcae35b92..847b3fc54e476 100644 --- a/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/ReadmeSamples.java +++ b/sdk/storage/azure-storage-blob-batch/src/samples/java/com/azure/storage/blob/batch/ReadmeSamples.java @@ -23,12 +23,12 @@ * Code samples for the README.md */ public class ReadmeSamples { - private BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().buildClient(); + private BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().endpoint("").sasToken("").buildClient(); private BlobBatchClient blobBatchClient = new BlobBatchClientBuilder(blobServiceClient).buildClient(); - private String blobUrl = "https://account.core.windows.net/containerName/blobName"; - private String blobUrl2 = "https://account.core.windows.net/containerName/blobName2"; - private String blobUrlWithSnapshot = "https://account.core.windows.net/containerName/blobName?snapshot="; - private String blobUrlWithLease = "https://account.core.windows.net/containerName/blobNameWithLease"; + private String blobUrl = String.format("https://%s.blob.core.windows.net/containerName/blobName", ""); + private String blobUrl2 = String.format("https://%s.blob.core.windows.net/containerName/blobName2", ""); + private String blobUrlWithSnapshot = String.format("https://%s.blob.core.windows.net/containerName/blobName?snapshot=", ""); + private String blobUrlWithLease = String.format("https://%s.blob.core.windows.net/containerName/blobNameWithLease", ""); private List blobUrls = Arrays.asList(blobUrl, blobUrl2, blobUrlWithSnapshot, blobUrlWithLease); public void createHttpClient() {