Class AppendBlobAsyncClient

java.lang.Object
com.azure.storage.blob.specialized.BlobAsyncClientBase
com.azure.storage.blob.specialized.AppendBlobAsyncClient

public final class AppendBlobAsyncClient extends BlobAsyncClientBase
Client to an append blob. It may only be instantiated through a SpecializedBlobClientBuilder.buildAppendBlobAsyncClient() or via the method BlobAsyncClient.getAppendBlobAsyncClient(). This class does not hold any state about a particular blob, but is instead a convenient way of sending appropriate requests to the resource on the service.

This client contains operations on a blob. Operations on a container are available on BlobContainerAsyncClient, and operations on the service are available on BlobServiceAsyncClient.

Please refer to the Azure Docs for more information.

Note this client is an async client that returns reactive responses from Spring Reactor Core project (https://projectreactor.io/). Calling the methods in this client will NOT start the actual network operation, until .subscribe() is called on the reactive response. You can simply convert one of these responses to a CompletableFuture object through Mono.toFuture().

  • Field Details

    • MAX_APPEND_BLOCK_BYTES

      public static final int MAX_APPEND_BLOCK_BYTES
      Indicates the maximum number of bytes that can be sent in a call to appendBlock.
      See Also:
    • MAX_BLOCKS

      public static final int MAX_BLOCKS
      Indicates the maximum number of blocks allowed in an append blob.
      See Also:
  • Method Details

    • getEncryptionScopeAsyncClient

      public AppendBlobAsyncClient getEncryptionScopeAsyncClient(String encryptionScope)
      Creates a new AppendBlobAsyncClient with the specified encryptionScope.
      Overrides:
      getEncryptionScopeAsyncClient in class BlobAsyncClientBase
      Parameters:
      encryptionScope - the encryption scope for the blob, pass null to use no encryption scope.
      Returns:
      a AppendBlobAsyncClient with the specified encryptionScope.
    • getCustomerProvidedKeyAsyncClient

      public AppendBlobAsyncClient getCustomerProvidedKeyAsyncClient(CustomerProvidedKey customerProvidedKey)
      Creates a new AppendBlobAsyncClient with the specified customerProvidedKey.
      Overrides:
      getCustomerProvidedKeyAsyncClient in class BlobAsyncClientBase
      Parameters:
      customerProvidedKey - the CustomerProvidedKey for the blob, pass null to use no customer provided key.
      Returns:
      a AppendBlobAsyncClient with the specified customerProvidedKey.
    • create

      public Mono<AppendBlobItem> create()
      Creates a 0-length append blob. Call appendBlock to append data to an append blob. By default this method will not overwrite an existing blob.

      Code Samples

       client.create().subscribe(response ->
           System.out.printf("Created AppendBlob at %s%n", response.getLastModified()));
       
      Returns:
      A Mono containing the information of the created appended blob.
    • create

      public Mono<AppendBlobItem> create(boolean overwrite)
      Creates a 0-length append blob. Call appendBlock to append data to an append blob.

      Code Samples

       boolean overwrite = false; // Default behavior
       client.create(overwrite).subscribe(response ->
           System.out.printf("Created AppendBlob at %s%n", response.getLastModified()));
       
      Parameters:
      overwrite - Whether to overwrite, should data exist on the blob.
      Returns:
      A Mono containing the information of the created appended blob.
    • createWithResponse

      public Mono<Response<AppendBlobItem>> createWithResponse(BlobHttpHeaders headers, Map<String,String> metadata, BlobRequestConditions requestConditions)
      Creates a 0-length append blob. Call appendBlock to append data to an append blob.

      To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String).

      Code Samples

       BlobHttpHeaders headers = new BlobHttpHeaders()
           .setContentType("binary")
           .setContentLanguage("en-US");
       Map<String, String> metadata = Collections.singletonMap("metadata", "value");
       BlobRequestConditions requestConditions = new BlobRequestConditions().setLeaseId(leaseId)
           .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
      
       client.createWithResponse(headers, metadata, requestConditions).subscribe(response ->
           System.out.printf("Created AppendBlob at %s%n", response.getValue().getLastModified()));
       
      Parameters:
      headers - BlobHttpHeaders
      metadata - Metadata to associate with the blob. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.
      requestConditions - BlobRequestConditions
      Returns:
      A Mono containing Response whose value contains the created appended blob.
    • createWithResponse

      public Mono<Response<AppendBlobItem>> createWithResponse(AppendBlobCreateOptions options)
      Creates a 0-length append blob. Call appendBlock to append data to an append blob.

      To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String).

      Code Samples

       BlobHttpHeaders headers = new BlobHttpHeaders()
           .setContentType("binary")
           .setContentLanguage("en-US");
       Map<String, String> metadata = Collections.singletonMap("metadata", "value");
       Map<String, String> tags = Collections.singletonMap("tag", "value");
       BlobRequestConditions requestConditions = new BlobRequestConditions().setLeaseId(leaseId)
           .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
      
       client.createWithResponse(new AppendBlobCreateOptions().setHeaders(headers).setMetadata(metadata)
           .setTags(tags).setRequestConditions(requestConditions)).subscribe(response ->
           System.out.printf("Created AppendBlob at %s%n", response.getValue().getLastModified()));
       
      Parameters:
      options - AppendBlobCreateOptions
      Returns:
      A Mono containing Response whose value contains the created appended blob.
    • createIfNotExists

      public Mono<AppendBlobItem> createIfNotExists()
      Creates a 0-length append blob if it does not exist. Call appendBlock to append data to an append blob.

      Code Samples

       client.createIfNotExists().subscribe(response ->
           System.out.printf("Created AppendBlob at %s%n", response.getLastModified()));
       
      Returns:
      A reactive response Mono signaling completion. AppendBlobItem contains the information of the created appended blob.
    • createIfNotExistsWithResponse

      public Mono<Response<AppendBlobItem>> createIfNotExistsWithResponse(AppendBlobCreateOptions options)
      Creates a 0-length append blob if it does not exist. Call appendBlock to append data to an append blob.

      Code Samples

       BlobHttpHeaders headers = new BlobHttpHeaders()
           .setContentType("binary")
           .setContentLanguage("en-US");
       Map<String, String> metadata = Collections.singletonMap("metadata", "value");
       Map<String, String> tags = Collections.singletonMap("tag", "value");
      
       client.createIfNotExistsWithResponse(new AppendBlobCreateOptions().setHeaders(headers)
           .setMetadata(metadata).setTags(tags)).subscribe(response -> {
               if (response.getStatusCode() == 409) {
                   System.out.println("Already exists.");
               } else {
                   System.out.println("successfully created.");
               }
           });
       
      Parameters:
      options - AppendBlobCreateOptions
      Returns:
      A Mono containing Response signaling completion, whose value contains a AppendBlobItem containing information about the append blob. If Response's status code is 201, a new page blob was successfully created. If status code is 409, an append blob already existed at this location.
    • appendBlock

      public Mono<AppendBlobItem> appendBlock(Flux<ByteBuffer> data, long length)
      Commits a new block of data to the end of the existing append blob.

      Note that the data passed 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.

      Code Samples

       client.appendBlock(data, length).subscribe(response ->
           System.out.printf("AppendBlob has %d committed blocks%n", response.getBlobCommittedBlockCount()));
       
      Parameters:
      data - The data to write to the blob. Note that this 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.
      length - The exact length of the data. It is important that this value match precisely the length of the data emitted by the Flux.
      Returns:
      Mono containing the information of the append blob operation.
    • appendBlockWithResponse

      public Mono<Response<AppendBlobItem>> appendBlockWithResponse(Flux<ByteBuffer> data, long length, byte[] contentMd5, AppendBlobRequestConditions appendBlobRequestConditions)
      Commits a new block of data to the end of the existing append blob.

      Note that the data passed 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.

      Code Samples

       byte[] md5 = MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8));
       AppendBlobRequestConditions requestConditions = new AppendBlobRequestConditions()
           .setAppendPosition(POSITION)
           .setMaxSize(maxSize);
      
       client.appendBlockWithResponse(data, length, md5, requestConditions).subscribe(response ->
           System.out.printf("AppendBlob has %d committed blocks%n", response.getValue().getBlobCommittedBlockCount()));
       
      Parameters:
      data - The data to write to the blob. Note that this 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.
      length - The exact length of the data. It is important that this value match precisely the length of the data emitted by the Flux.
      contentMd5 - An MD5 hash of the block content. This hash is used to verify the integrity of the block during transport. When this header is specified, the storage service compares the hash of the content that has arrived with this header value. Note that this MD5 hash is not stored with the blob. If the two hashes do not match, the operation will fail.
      appendBlobRequestConditions - AppendBlobRequestConditions
      Returns:
      A Mono containing Response whose value contains the append blob operation.
    • appendBlockFromUrl

      public Mono<AppendBlobItem> appendBlockFromUrl(String sourceUrl, BlobRange sourceRange)
      Commits a new block of data from another blob to the end of this append blob.

      Code Samples

       client.appendBlockFromUrl(sourceUrl, new BlobRange(offset, count)).subscribe(response ->
           System.out.printf("AppendBlob has %d committed blocks%n", response.getBlobCommittedBlockCount()));
       
      Parameters:
      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 public, no authentication is required to perform the operation.
      sourceRange - The source BlobRange to copy.
      Returns:
      Mono containing the information of the append blob operation.
    • appendBlockFromUrlWithResponse

      public Mono<Response<AppendBlobItem>> appendBlockFromUrlWithResponse(String sourceUrl, BlobRange sourceRange, byte[] sourceContentMD5, AppendBlobRequestConditions destRequestConditions, BlobRequestConditions sourceRequestConditions)
      Commits a new block of data from another blob to the end of this append blob.

      Code Samples

       AppendBlobRequestConditions appendBlobRequestConditions = new AppendBlobRequestConditions()
           .setAppendPosition(POSITION)
           .setMaxSize(maxSize);
      
       BlobRequestConditions modifiedRequestConditions = new BlobRequestConditions()
           .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
      
       client.appendBlockFromUrlWithResponse(sourceUrl, new BlobRange(offset, count), null,
           appendBlobRequestConditions, modifiedRequestConditions).subscribe(response ->
           System.out.printf("AppendBlob has %d committed blocks%n", response.getValue().getBlobCommittedBlockCount()));
       
      Parameters:
      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 public, no authentication is required to perform the operation.
      sourceRange - BlobRange
      sourceContentMD5 - An MD5 hash of the block content from the source blob. If specified, the service will calculate the MD5 of the received data and fail the request if it does not match the provided MD5.
      destRequestConditions - AppendBlobRequestConditions
      sourceRequestConditions - BlobRequestConditions
      Returns:
      A Mono containing Response whose value contains the append blob operation.
    • appendBlockFromUrlWithResponse

      public Mono<Response<AppendBlobItem>> appendBlockFromUrlWithResponse(AppendBlobAppendBlockFromUrlOptions options)
      Commits a new block of data from another blob to the end of this append blob.

      Code Samples

       AppendBlobRequestConditions appendBlobRequestConditions = new AppendBlobRequestConditions()
           .setAppendPosition(POSITION)
           .setMaxSize(maxSize);
      
       BlobRequestConditions modifiedRequestConditions = new BlobRequestConditions()
           .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
      
       client.appendBlockFromUrlWithResponse(new AppendBlobAppendBlockFromUrlOptions(sourceUrl)
           .setSourceRange(new BlobRange(offset, count))
           .setDestinationRequestConditions(appendBlobRequestConditions)
           .setSourceRequestConditions(modifiedRequestConditions)).subscribe(response ->
           System.out.printf("AppendBlob has %d committed blocks%n", response.getValue().getBlobCommittedBlockCount()));
       
      Parameters:
      options - Parameters for the operation.
      Returns:
      A Mono containing Response whose value contains the append blob operation.
    • seal

      public Mono<Void> seal()
      Seals an append blob, making it read only. Any subsequent appends will fail.

      Code Samples

       client.seal().subscribe(response -> System.out.println("Sealed AppendBlob"));
       
      Returns:
      A reactive response signalling completion.
    • sealWithResponse

      public Mono<Response<Void>> sealWithResponse(AppendBlobSealOptions options)
      Seals an append blob, making it read only. Any subsequent appends will fail.

      Code Samples

       AppendBlobRequestConditions requestConditions = new AppendBlobRequestConditions().setLeaseId(leaseId)
           .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
      
       client.sealWithResponse(new AppendBlobSealOptions().setRequestConditions(requestConditions))
           .subscribe(response -> System.out.println("Sealed AppendBlob"));
       
      Parameters:
      options - AppendBlobSealOptions
      Returns:
      A reactive response signalling completion.