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

adding code snippets for BlockBlob Async and sync clients #5249

Merged
merged 3 commits 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 @@ -113,6 +113,10 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient {
* {@code Flux} must produce the same data each time it is subscribed to.
* <p>
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.upload#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 @@ -137,6 +141,10 @@ public Mono<BlockBlobItem> upload(Flux<ByteBuffer> data, long length) {
* {@code Flux} must produce the same data each time it is subscribed to.
* <p>
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.uploadWithResponse#Flux-long-BlobHTTPHeaders-Metadata-AccessTier-BlobAccessConditions}
*
* @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 @@ -189,6 +197,10 @@ Mono<Response<BlockBlobItem>> uploadWithResponse(Flux<ByteBuffer> data, long len
* trade-offs between these values are context-dependent, so some experimentation may be required to optimize inputs
* for a given scenario.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.upload#Flux-int-int}
*
* @param data The data to write to the blob. Unlike other upload methods, this method does not require that the
* {@code Flux} be replayable. In other words, it does not have to support multiple subscribers and is
* not expected to produce the same values across subscriptions.
Expand Down Expand Up @@ -228,6 +240,10 @@ public Mono<BlockBlobItem> upload(Flux<ByteBuffer> data, int blockSize, int numB
* trade-offs between these values are context-dependent, so some experimentation may be required to optimize inputs
* for a given scenario.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.uploadWithResponse#Flux-int-int-BlobHTTPHeaders-Metadata-AccessTier-BlobAccessConditions}
*
* @param data The data to write to the blob. Unlike other upload methods, this method does not require that the
* {@code Flux} be replayable. In other words, it does not have to support multiple subscribers and is
* not expected to produce the same values across subscriptions.
Expand Down Expand Up @@ -310,6 +326,11 @@ as we can guarantee we only need at most two buffers for any call to write (two

/**
* Creates a new block blob, or updates the content of an existing block blob, with the content of the specified file.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.uploadFromFile#String}
*
* @param filePath Path to the upload file
*
* @return An empty response
Expand All @@ -320,6 +341,11 @@ public Mono<Void> uploadFromFile(String filePath) {

/**
* Creates a new block blob, or updates the content of an existing block blob, with the content of the specified file.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.uploadFromFile#String-Integer-BlobHTTPHeaders-Metadata-AccessTier-BlobAccessConditions}
*
* @param filePath Path to the upload file
* @param blockSize Size of the blocks to upload
* @param headers {@link BlobHTTPHeaders}
Expand Down Expand Up @@ -406,6 +432,10 @@ private List<BlobRange> sliceFile(String path, Integer blockSize) {
* 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.BlockBlobAsyncClient.stageBlock#String-Flux-long}
*
* @param base64BlockID A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given
* blob must be the same length.
* @param data The data to write to the block. Note that this {@code Flux} must be replayable if retries are enabled
Expand All @@ -427,6 +457,10 @@ public Mono<Void> stageBlock(String base64BlockID, Flux<ByteBuffer> data, long l
* 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.BlockBlobAsyncClient.stageBlockWithResponse#String-Flux-long-LeaseAccessConditions}
*
* @param base64BlockID A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given
* blob must be the same length.
* @param data The data to write to the block. Note that this {@code Flux} must be replayable if retries are enabled
Expand Down Expand Up @@ -454,6 +488,10 @@ Mono<VoidResponse> stageBlockWithResponse(String base64BlockID, Flux<ByteBuffer>
* Creates a new block to be committed as part of a blob where the contents are read from a URL. For more
* information, see the <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-from-url">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.stageBlockFromURL#String-URL-BlobRange}
*
* @param base64BlockID A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given
* blob must be the same length.
* @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
Expand All @@ -473,6 +511,10 @@ public Mono<Void> stageBlockFromURL(String base64BlockID, URL sourceURL, BlobRan
* Creates a new block to be committed as part of a blob where the contents are read from a URL. For more
* information, see the <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-from-url">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.stageBlockFromURLWithResponse#String-URL-BlobRange-byte-LeaseAccessConditions-SourceModifiedAccessConditions}
*
* @param base64BlockID A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given
* blob must be the same length.
* @param sourceURL The url to the blob that will be the source of the copy. A source blob in the same storage account can
Expand Down Expand Up @@ -512,30 +554,44 @@ Mono<VoidResponse> stageBlockFromURLWithResponse(String base64BlockID, URL sourc
* For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/get-block-list">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.listBlocks#BlockListType}
*
* @param listType Specifies which type of blocks to return.
*
* @return A reactive response containing the list of blocks.
*/
public Mono<BlockList> listBlocks(BlockListType listType) {
return this.listBlocks(listType, null).map(Response::value);
return this.listBlocksWithResponse(listType, null).map(Response::value);
}

/**
* Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter.
* For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/get-block-list">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.listBlocksWithResponse#BlockListType-LeaseAccessConditions}
*
* @param listType Specifies which type of blocks to return.
* @param leaseAccessConditions By setting lease access conditions, requests will fail if the provided lease does not match the active
* lease on the blob.
*
* @return A reactive response containing the list of blocks.
*/
public Mono<Response<BlockList>> listBlocks(BlockListType listType,
public Mono<Response<BlockList>> listBlocksWithResponse(BlockListType listType,
LeaseAccessConditions leaseAccessConditions) {

return postProcessResponse(this.azureBlobStorage.blockBlobs().getBlockListWithRestResponseAsync(
null, null, listType, snapshot, null, null, leaseAccessConditions, Context.NONE))
return withContext(context -> listBlocksWithResponse(listType, leaseAccessConditions, context));
}

Mono<Response<BlockList>> listBlocksWithResponse(BlockListType listType,
LeaseAccessConditions leaseAccessConditions, Context context) {

return postProcessResponse(this.azureBlobStorage.blockBlobs().getBlockListWithRestResponseAsync(null,
null, listType, snapshot, null, null, leaseAccessConditions, context))
.map(response -> new SimpleResponse<>(response, response.value()));
}

Expand All @@ -548,6 +604,10 @@ public Mono<Response<BlockList>> listBlocks(BlockListType listType,
* For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/put-block-list">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.commitBlockList#List}
*
* @param base64BlockIDs A list of base64 encode {@code String}s that specifies the block IDs to be committed.
*
* @return A reactive response containing the information of the block blob.
Expand All @@ -565,6 +625,10 @@ public Mono<BlockBlobItem> commitBlockList(List<String> base64BlockIDs) {
* For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/put-block-list">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobAsyncClient.commitBlockListWithResponse#List-BlobHTTPHeaders-Metadata-AccessTier-BlobAccessConditions}
*
* @param base64BlockIDs A list of base64 encode {@code String}s that specifies the block IDs to be committed.
* @param headers {@link BlobHTTPHeaders}
* @param metadata {@link Metadata}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public BlobOutputStream getBlobOutputStream(BlobAccessConditions accessCondition
* For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/put-blob">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.upload#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
* provided in the {@link InputStream}.
Expand All @@ -126,6 +130,10 @@ public BlockBlobItem upload(InputStream data, long length) throws IOException {
* For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/put-blob">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.uploadWithResponse#InputStream-long-BlobHTTPHeaders-Metadata-AccessTier-BlobAccessConditions-Duration-Context}
*
* @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
* provided in the {@link InputStream}.
Expand Down Expand Up @@ -158,6 +166,11 @@ public Response<BlockBlobItem> uploadWithResponse(InputStream data, long length,

/**
* Creates a new block blob, or updates the content of an existing block blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.uploadFromFile#String}
*
* @param filePath Path of the file to upload
*
* @throws IOException If an I/O error occurs
Expand All @@ -168,6 +181,11 @@ public void uploadFromFile(String filePath) throws IOException {

/**
* Creates a new block blob, or updates the content of an existing block blob.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.uploadFromFile#String-BlobHTTPHeaders-Metadata-AccessTier-BlobAccessConditions-Duration}
*
* @param filePath Path of the file to upload
* @param headers {@link BlobHTTPHeaders}
* @param metadata {@link Metadata}
Expand All @@ -194,6 +212,10 @@ public void uploadFromFile(String filePath, BlobHTTPHeaders headers, Metadata me
* commitBlockList. For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/put-block">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.stageBlock#String-InputStream-long}
*
* @param base64BlockID A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given
* blob must be the same length.
* @param data The data to write to the block.
Expand All @@ -209,6 +231,10 @@ public void stageBlock(String base64BlockID, InputStream data, long length) {
* commitBlockList. For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/put-block">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.stageBlockWithResponse#String-InputStream-long-LeaseAccessConditions-Duration-Context}
*
* @param base64BlockID A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given
* blob must be the same length.
* @param data The data to write to the block.
Expand Down Expand Up @@ -237,6 +263,10 @@ public VoidResponse stageBlockWithResponse(String base64BlockID, InputStream dat
* Creates a new block to be committed as part of a blob where the contents are read from a URL. For more
* information, see the <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-from-url">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.stageBlockFromURL#String-URL-BlobRange}
*
* @param base64BlockID A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given
* blob must be the same length.
* @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
Expand All @@ -253,6 +283,10 @@ public void stageBlockFromURL(String base64BlockID, URL sourceURL, BlobRange sou
* Creates a new block to be committed as part of a blob where the contents are read from a URL. For more
* information, see the <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-from-url">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.stageBlockFromURLWithResponse#String-URL-BlobRange-byte-LeaseAccessConditions-SourceModifiedAccessConditions-Duration-Context}
*
* @param base64BlockID A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given
* blob must be the same length.
* @param sourceURL The url to the blob that will be the source of the copy. A source blob in the same storage account can
Expand Down Expand Up @@ -283,29 +317,38 @@ public VoidResponse stageBlockFromURLWithResponse(String base64BlockID, URL sour
* For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/get-block-list">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.listBlocks#BlockListType}
*
* @param listType Specifies which type of blocks to return.
*
* @return The list of blocks.
*/
public BlockList listBlocks(BlockListType listType) {
return this.listBlocksWithResponse(listType, null, null).value();
return this.listBlocksWithResponse(listType, null, null, Context.NONE).value();
}

/**
* Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter.
* For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/get-block-list">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.listBlocksWithResponse#BlockListType-LeaseAccessConditions-Duration-Context}
*
* @param listType Specifies which type of blocks to return.
* @param leaseAccessConditions By setting lease access conditions, requests will fail if the provided lease does not match the active
* lease on the blob.
* @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised.
* @param context Additional context that is passed through the Http pipeline during the service call.
*
* @return The list of blocks.
*/
public Response<BlockList> listBlocksWithResponse(BlockListType listType,
LeaseAccessConditions leaseAccessConditions, Duration timeout) {
Mono<Response<BlockList>> response = blockBlobAsyncClient.listBlocks(listType, leaseAccessConditions);
LeaseAccessConditions leaseAccessConditions, Duration timeout, Context context) {
Mono<Response<BlockList>> response = blockBlobAsyncClient.listBlocksWithResponse(listType, leaseAccessConditions, context);

return Utility.blockWithOptionalTimeout(response, timeout);
}
Expand All @@ -319,6 +362,10 @@ public Response<BlockList> listBlocksWithResponse(BlockListType listType,
* For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/put-block-list">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.commitBlockList#List}
*
* @param base64BlockIDs A list of base64 encode {@code String}s that specifies the block IDs to be committed.
*
* @return The information of the block blob.
Expand All @@ -336,6 +383,10 @@ public BlockBlobItem commitBlockList(List<String> base64BlockIDs) {
* For more information, see the
* <a href="https://docs.microsoft.com/rest/api/storageservices/put-block-list">Azure Docs</a>.
*
* <p><strong>Code Samples</strong></p>
*
* {@codesnippet com.azure.storage.blob.BlockBlobClient.commitBlockListWithResponse#List-BlobHTTPHeaders-Metadata-AccessTier-BlobAccessConditions-Duration-Context}
*
* @param base64BlockIDs A list of base64 encode {@code String}s that specifies the block IDs to be committed.
* @param headers {@link BlobHTTPHeaders}
* @param metadata {@link Metadata}
Expand Down
Loading