Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance code samples blob storage 4320 #5245

Merged
merged 1 commit into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ page at http://checkstyle.sourceforge.net/config.html -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<module name="JavadocMethod">
<property name="scope" value="protected"/>
<property name="suppressLoadErrors" value="true"/>
</module>

<!-- Verifies that all throws in the public API have JavaDocs explaining why and when they are thrown. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public final class AppendBlobAsyncClient extends BlobAsyncClient {
/**
* Creates a 0-length append blob. Call appendBlock to append data to an append blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobAsyncClient.create}
*
* @return A {@link Mono} containing the information of the created appended blob.
*/
public Mono<AppendBlobItem> create() {
Expand All @@ -79,6 +83,11 @@ public Mono<AppendBlobItem> create() {

/**
* Creates a 0-length append blob. Call appendBlock to append data to an append blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobAsyncClient.createWithResponse#BlobHTTPHeaders-Metadata-BlobAccessConditions}
*
* @param headers {@link BlobHTTPHeaders}
* @param metadata {@link Metadata}
* @param accessConditions {@link BlobAccessConditions}
Expand All @@ -104,6 +113,11 @@ Mono<Response<AppendBlobItem>> createWithResponse(BlobHTTPHeaders headers, Metad
* <p>
* Note that the data passed must be replayable if retries are enabled (the default). In other words, the
* {@code Flux} must produce the same data each time it is subscribed to.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobAsyncClient.appendBlock#Flux-long}
*
* @param data The data to write to the blob. Note that this {@code Flux} must be replayable if retries are enabled
* (the default). In other words, the Flux must produce the same data each time it is subscribed to.
* @param length The exact length of the data. It is important that this value match precisely the length of the data
Expand All @@ -120,6 +134,11 @@ public Mono<AppendBlobItem> appendBlock(Flux<ByteBuffer> data, long length) {
* <p>
* Note that the data passed must be replayable if retries are enabled (the default). In other words, the
* {@code Flux} must produce the same data each time it is subscribed to.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobAsyncClient.appendBlockWithResponse#Flux-long-AppendBlobAccessConditions}
*
* @param data The data to write to the blob. Note that this {@code Flux} must be replayable if retries are enabled
* (the default). In other words, the Flux must produce the same data each time it is subscribed to.
* @param length The exact length of the data. It is important that this value match precisely the length of the data
Expand Down Expand Up @@ -149,6 +168,11 @@ Mono<Response<AppendBlobItem>> appendBlockWithResponse(Flux<ByteBuffer> data, lo

/**
* Commits a new block of data from another blob to the end of this append blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobAsyncClient.appendBlockFromUrl#URL-BlobRange}
*
* @param sourceURL The url to the blob that will be the source of the copy. A source blob in the same storage account can
* be authenticated via Shared Key. However, if the source is a blob in another account, the source blob
* must either be public or must be authenticated via a shared access signature. If the source blob is
Expand All @@ -163,6 +187,11 @@ public Mono<AppendBlobItem> appendBlockFromUrl(URL sourceURL, BlobRange sourceRa

/**
* Commits a new block of data from another blob to the end of this append blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobAsyncClient.appendBlockFromUrlWithResponse#URL-BlobRange-byte-AppendBlobAccessConditions-SourceModifiedAccessConditions}
*
* @param sourceURL The url to the blob that will be the source of the copy. A source blob in the same storage account can
* be authenticated via Shared Key. However, if the source is a blob in another account, the source blob
* must either be public or must be authenticated via a shared access signature. If the source blob is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public BlobOutputStream getBlobOutputStream(AppendBlobAccessConditions accessCon
/**
* Creates a 0-length append blob. Call appendBlock to append data to an append blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobClient.create}
*
* @return The information of the created appended blob.
*/
public AppendBlobItem create() {
Expand All @@ -101,6 +105,10 @@ public AppendBlobItem create() {
/**
* Creates a 0-length append blob. Call appendBlock to append data to an append blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobClient.create#BlobHTTPHeaders-Metadata-BlobAccessConditions-Duration}
*
* @param headers {@link BlobHTTPHeaders}
* @param metadata {@link Metadata}
* @param accessConditions {@link BlobAccessConditions}
Expand All @@ -116,6 +124,10 @@ public AppendBlobItem create(BlobHTTPHeaders headers, Metadata metadata,
/**
* Creates a 0-length append blob. Call appendBlock to append data to an append blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobClient.createWithResponse#BlobHTTPHeaders-Metadata-BlobAccessConditions-Duration-Context}
*
* @param headers {@link BlobHTTPHeaders}
* @param metadata {@link Metadata}
* @param accessConditions {@link BlobAccessConditions}
Expand All @@ -136,6 +148,10 @@ public Response<AppendBlobItem> createWithResponse(BlobHTTPHeaders headers, Meta
* Note that the data passed must be replayable if retries are enabled (the default). In other words, the
* {@code Flux} must produce the same data each time it is subscribed to.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobClient.appendBlock#InputStream-long}
*
* @param data The data to write to the blob.
* @param length The exact length of the data. It is important that this value match precisely the length of the data
* emitted by the {@code Flux}.
Expand All @@ -152,6 +168,10 @@ public AppendBlobItem appendBlock(InputStream data, long length) {
* Note that the data passed must be replayable if retries are enabled (the default). In other words, the
* {@code Flux} must produce the same data each time it is subscribed to.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobClient.appendBlockWithResponse#InputStream-long-AppendBlobAccessConditions-Duration-Context}
*
* @param data The data to write to the blob. Note that this {@code Flux} must be replayable if retries are enabled
* (the default). In other words, the Flux must produce the same data each time it is subscribed to.
* @param length The exact length of the data. It is important that this value match precisely the length of the data
Expand All @@ -175,6 +195,10 @@ public Response<AppendBlobItem> appendBlockWithResponse(InputStream data, long l
/**
* Commits a new block of data from another blob to the end of this append blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobClient.appendBlockFromUrl#URL-BlobRange}
*
* @param sourceURL The url to the blob that will be the source of the copy. A source blob in the same storage account can
* be authenticated via Shared Key. However, if the source is a blob in another account, the source blob
* must either be public or must be authenticated via a shared access signature. If the source blob is
Expand All @@ -190,6 +214,10 @@ public AppendBlobItem appendBlockFromUrl(URL sourceURL, BlobRange sourceRange) {
/**
* Commits a new block of data from another blob to the end of this append blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobClient.appendBlockFromUrl#URL-BlobRange-byte-AppendBlobAccessConditions-SourceModifiedAccessConditions-Duration}
*
* @param sourceURL The url to the blob that will be the source of the copy. A source blob in the same storage account can
* be authenticated via Shared Key. However, if the source is a blob in another account, the source blob
* must either be public or must be authenticated via a shared access signature. If the source blob is
Expand All @@ -213,6 +241,10 @@ public AppendBlobItem appendBlockFromUrl(URL sourceURL, BlobRange sourceRange,
/**
* Commits a new block of data from another blob to the end of this append blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.AppendBlobClient.appendBlockFromUrlWithResponse#URL-BlobRange-byte-AppendBlobAccessConditions-SourceModifiedAccessConditions-Duration-Context}
*
* @param sourceURL The url to the blob that will be the source of the copy. A source blob in the same storage account can
* be authenticated via Shared Key. However, if the source is a blob in another account, the source blob
* must either be public or must be authenticated via a shared access signature. If the source blob is
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.blob;

import com.azure.storage.blob.models.AppendBlobAccessConditions;
import com.azure.storage.blob.models.AppendPositionAccessConditions;
import com.azure.storage.blob.models.BlobAccessConditions;
import com.azure.storage.blob.models.BlobHTTPHeaders;
import com.azure.storage.blob.models.BlobRange;
import com.azure.storage.blob.models.LeaseAccessConditions;
import com.azure.storage.blob.models.Metadata;
import com.azure.storage.blob.models.ModifiedAccessConditions;
import com.azure.storage.blob.models.SourceModifiedAccessConditions;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import reactor.core.publisher.Flux;

import java.net.URL;
import java.time.OffsetDateTime;
import java.util.Collections;

/**
* Code snippets for {@link AppendBlobAsyncClient}
*/
public class AppendBlobAsyncClientJavaDocCodeSnippets {
private AppendBlobAsyncClient client = JavaDocCodeSnippetsHelpers.getBlobAsyncClient("blobName")
.asAppendBlobAsyncClient();
private String leaseId = "leaseId";
private Flux<ByteBuffer> data = Flux.just(ByteBuffer.wrap("data".getBytes("UTF-8")));
private long length = 4L;
private static final Long POSITION = null;
private Long maxSize = length;
private URL sourceUrl = JavaDocCodeSnippetsHelpers.generateURL("https://example.com");
private long offset = 1024;
private long count = 1024;

/**
*
* @throws UnsupportedEncodingException if cannot get bytes from sample sting as utf-8 encoding
*/
AppendBlobAsyncClientJavaDocCodeSnippets() throws UnsupportedEncodingException {
}

/**
* Code snippet for {@link AppendBlobAsyncClient#create()}
*/
public void create() {
// BEGIN: com.azure.storage.blob.AppendBlobAsyncClient.create
client.create().subscribe(response ->
System.out.printf("Created AppendBlob at %s%n", response.lastModified()));
// END: com.azure.storage.blob.AppendBlobAsyncClient.create
}

/**
* Code snippet for {@link AppendBlobAsyncClient#createWithResponse(BlobHTTPHeaders, Metadata, BlobAccessConditions)}
*/
public void create2() {
// BEGIN: com.azure.storage.blob.AppendBlobAsyncClient.createWithResponse#BlobHTTPHeaders-Metadata-BlobAccessConditions
BlobHTTPHeaders headers = new BlobHTTPHeaders()
.blobContentType("binary")
.blobContentLanguage("en-US");
Metadata metadata = new Metadata(Collections.singletonMap("metadata", "value"));
BlobAccessConditions accessConditions = new BlobAccessConditions()
.leaseAccessConditions(new LeaseAccessConditions().leaseId(leaseId))
.modifiedAccessConditions(new ModifiedAccessConditions()
.ifUnmodifiedSince(OffsetDateTime.now().minusDays(3)));

client.createWithResponse(headers, metadata, accessConditions).subscribe(response ->
System.out.printf("Created AppendBlob at %s%n", response.value().lastModified()));
// END: com.azure.storage.blob.AppendBlobAsyncClient.createWithResponse#BlobHTTPHeaders-Metadata-BlobAccessConditions
}

/**
* Code snippet for {@link AppendBlobAsyncClient#appendBlock(Flux, long)}
*/
public void appendBlock() {
// BEGIN: com.azure.storage.blob.AppendBlobAsyncClient.appendBlock#Flux-long
client.appendBlock(data, length).subscribe(response ->
System.out.printf("AppendBlob has %d committed blocks%n", response.blobCommittedBlockCount()));
// END: com.azure.storage.blob.AppendBlobAsyncClient.appendBlock#Flux-long
}

/**
* Code snippet for {@link AppendBlobAsyncClient#appendBlockWithResponse(Flux, long, AppendBlobAccessConditions)}
*/
public void appendBlock2() {
// BEGIN: com.azure.storage.blob.AppendBlobAsyncClient.appendBlockWithResponse#Flux-long-AppendBlobAccessConditions
AppendBlobAccessConditions accessConditions = new AppendBlobAccessConditions()
.appendPositionAccessConditions(new AppendPositionAccessConditions()
.appendPosition(POSITION)
.maxSize(maxSize));

client.appendBlockWithResponse(data, length, accessConditions).subscribe(response ->
System.out.printf("AppendBlob has %d committed blocks%n", response.value().blobCommittedBlockCount()));
// END: com.azure.storage.blob.AppendBlobAsyncClient.appendBlockWithResponse#Flux-long-AppendBlobAccessConditions
}

/**
* Code snippet for {@link AppendBlobAsyncClient#appendBlockFromUrl(URL, BlobRange)}
*/
public void appendBlockFromUrl() {
// BEGIN: com.azure.storage.blob.AppendBlobAsyncClient.appendBlockFromUrl#URL-BlobRange
client.appendBlockFromUrl(sourceUrl, new BlobRange(offset, count)).subscribe(response ->
System.out.printf("AppendBlob has %d committed blocks%n", response.blobCommittedBlockCount()));
// END: com.azure.storage.blob.AppendBlobAsyncClient.appendBlockFromUrl#URL-BlobRange
}

/**
* Code snippet for {@link AppendBlobAsyncClient#appendBlockFromUrlWithResponse(URL, BlobRange, byte[], AppendBlobAccessConditions, SourceModifiedAccessConditions)}
*/
public void appendBlockFromUrl2() {
// BEGIN: com.azure.storage.blob.AppendBlobAsyncClient.appendBlockFromUrlWithResponse#URL-BlobRange-byte-AppendBlobAccessConditions-SourceModifiedAccessConditions
AppendBlobAccessConditions appendBlobAccessConditions = new AppendBlobAccessConditions()
.appendPositionAccessConditions(new AppendPositionAccessConditions()
.appendPosition(POSITION)
.maxSize(maxSize));

SourceModifiedAccessConditions modifiedAccessConditions = new SourceModifiedAccessConditions()
.sourceIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

client.appendBlockFromUrlWithResponse(sourceUrl, new BlobRange(offset, count), null,
appendBlobAccessConditions, modifiedAccessConditions).subscribe(response ->
System.out.printf("AppendBlob has %d committed blocks%n", response.value().blobCommittedBlockCount()));
// END: com.azure.storage.blob.AppendBlobAsyncClient.appendBlockFromUrlWithResponse#URL-BlobRange-byte-AppendBlobAccessConditions-SourceModifiedAccessConditions
}
}
Loading