Class AppendBlobClient

    • Field Detail

      • 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:
        Constant Field Values
      • MAX_BLOCKS

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

      • getBlobOutputStream

        public BlobOutputStream getBlobOutputStream()
        Creates and opens an output stream to write data to the append blob. If the blob already exists on the service, it will be overwritten.
        Returns:
        A BlobOutputStream object used to write data to the blob.
        Throws:
        BlobStorageException - If a storage service error occurred.
      • getBlobOutputStream

        public BlobOutputStream getBlobOutputStream​(AppendBlobRequestConditions requestConditions)
        Creates and opens an output stream to write data to the append blob. If the blob already exists on the service, it will be overwritten.
        Parameters:
        requestConditions - A BlobRequestConditions object that represents the access conditions for the blob.
        Returns:
        A BlobOutputStream object used to write data to the blob.
        Throws:
        BlobStorageException - If a storage service error occurred.
      • create

        public 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

         System.out.printf("Created AppendBlob at %s%n", client.create().getLastModified());
         
        Returns:
        The information of the created appended blob.
      • create

        public 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 value
         System.out.printf("Created AppendBlob at %s%n", client.create(overwrite).getLastModified());
         
        Parameters:
        overwrite - Whether or not to overwrite, should data exist on the blob.
        Returns:
        The information of the created appended blob.
      • createWithResponse

        public com.azure.core.http.rest.Response<AppendBlobItem> createWithResponse​(BlobHttpHeaders headers,
                                                                                    Map<String,​String> metadata,
                                                                                    BlobRequestConditions requestConditions,
                                                                                    Duration timeout,
                                                                                    com.azure.core.util.Context context)
        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));
         Context context = new Context("key", "value");
        
         System.out.printf("Created AppendBlob at %s%n",
             client.createWithResponse(headers, metadata, requestConditions, timeout, context).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
        timeout - An optional timeout value beyond which a RuntimeException will be raised.
        context - Additional context that is passed through the Http pipeline during the service call.
        Returns:
        A Response whose value contains the created appended blob.
      • createWithResponse

        public com.azure.core.http.rest.Response<AppendBlobItem> createWithResponse​(AppendBlobCreateOptions options,
                                                                                    Duration timeout,
                                                                                    com.azure.core.util.Context context)
        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("tags", "value");
         BlobRequestConditions requestConditions = new BlobRequestConditions()
             .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
         Context context = new Context("key", "value");
        
         System.out.printf("Created AppendBlob at %s%n",
             client.createWithResponse(new AppendBlobCreateOptions().setHeaders(headers).setMetadata(metadata)
                 .setTags(tags).setRequestConditions(requestConditions), timeout, context).getValue()
                 .getLastModified());
         
        Parameters:
        options - AppendBlobCreateOptions
        timeout - An optional timeout value beyond which a RuntimeException will be raised.
        context - Additional context that is passed through the Http pipeline during the service call.
        Returns:
        A Response whose value contains the created appended blob.
      • createIfNotExists

        public 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();
         System.out.println("Created AppendBlob");
         
        Returns:
        AppendBlobItem containing information of the created appended blob.
      • createIfNotExistsWithResponse

        public com.azure.core.http.rest.Response<AppendBlobItem> createIfNotExistsWithResponse​(AppendBlobCreateOptions options,
                                                                                               Duration timeout,
                                                                                               com.azure.core.util.Context context)
        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("tags", "value");
         Context context = new Context("key", "value");
        
         Response<AppendBlobItem> response = client.createIfNotExistsWithResponse(new AppendBlobCreateOptions()
             .setHeaders(headers).setMetadata(metadata).setTags(tags), timeout, context);
         if (response.getStatusCode() == 409) {
             System.out.println("Already existed.");
         } else {
             System.out.printf("Create completed with status %d%n", response.getStatusCode());
         }
         
        Parameters:
        options - AppendBlobCreateOptions
        timeout - An optional timeout value beyond which a RuntimeException will be raised.
        context - Additional context that is passed through the Http pipeline during the service call.
        Returns:
        A reactive response Response signaling completion, whose value contains the AppendBlobItem containing information about the append blob. If Response's status code is 201, a new append blob was successfully created. If status code is 409, an append blob already existed at this location.
      • appendBlock

        public AppendBlobItem appendBlock​(InputStream 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

         System.out.printf("AppendBlob has %d committed blocks%n",
             client.appendBlock(data, length).getBlobCommittedBlockCount());
         
        Parameters:
        data - The data to write to the blob. The data must be markable. This is in order to support retries. If the data is not markable, consider using getBlobOutputStream() and writing to the returned OutputStream. Alternatively, consider wrapping your data source in a BufferedInputStream to add mark support.
        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:
        The information of the append blob operation.
      • appendBlockWithResponse

        public com.azure.core.http.rest.Response<AppendBlobItem> appendBlockWithResponse​(InputStream data,
                                                                                         long length,
                                                                                         byte[] contentMd5,
                                                                                         AppendBlobRequestConditions appendBlobRequestConditions,
                                                                                         Duration timeout,
                                                                                         com.azure.core.util.Context context)
        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);
         Context context = new Context("key", "value");
        
         System.out.printf("AppendBlob has %d committed blocks%n",
             client.appendBlockWithResponse(data, length, md5, requestConditions, timeout, context)
                 .getValue().getBlobCommittedBlockCount());
         
        Parameters:
        data - The data to write to the blob. The data must be markable. This is in order to support retries. If the data is not markable, consider using getBlobOutputStream() and writing to the returned OutputStream. Alternatively, consider wrapping your data source in a BufferedInputStream to add mark support.
        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
        timeout - An optional timeout value beyond which a RuntimeException will be raised.
        context - Additional context that is passed through the Http pipeline during the service call.
        Returns:
        A Response whose value contains the append blob operation.
        Throws:
        com.azure.core.exception.UnexpectedLengthException - when the length of data does not match the input length.
        NullPointerException - if the input data is null.
      • appendBlockFromUrl

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

        Code Samples

         System.out.printf("AppendBlob has %d committed blocks%n",
             client.appendBlockFromUrl(sourceUrl, new BlobRange(offset, count)).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:
        The information of the append blob operation.
      • appendBlockFromUrlWithResponse

        public com.azure.core.http.rest.Response<AppendBlobItem> appendBlockFromUrlWithResponse​(String sourceUrl,
                                                                                                BlobRange sourceRange,
                                                                                                byte[] sourceContentMd5,
                                                                                                AppendBlobRequestConditions destRequestConditions,
                                                                                                BlobRequestConditions sourceRequestConditions,
                                                                                                Duration timeout,
                                                                                                com.azure.core.util.Context context)
        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));
        
         Context context = new Context("key", "value");
        
         System.out.printf("AppendBlob has %d committed blocks%n",
             client.appendBlockFromUrlWithResponse(sourceUrl, new BlobRange(offset, count), null,
                 appendBlobRequestConditions, modifiedRequestConditions, timeout,
                 context).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
        timeout - An optional timeout value beyond which a RuntimeException will be raised.
        context - Additional context that is passed through the Http pipeline during the service call.
        Returns:
        The information of the append blob operation.
      • appendBlockFromUrlWithResponse

        public com.azure.core.http.rest.Response<AppendBlobItem> appendBlockFromUrlWithResponse​(AppendBlobAppendBlockFromUrlOptions options,
                                                                                                Duration timeout,
                                                                                                com.azure.core.util.Context context)
        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));
        
         Context context = new Context("key", "value");
        
         System.out.printf("AppendBlob has %d committed blocks%n",
             client.appendBlockFromUrlWithResponse(new AppendBlobAppendBlockFromUrlOptions(sourceUrl)
                 .setSourceRange(new BlobRange(offset, count))
                 .setDestinationRequestConditions(appendBlobRequestConditions)
                 .setSourceRequestConditions(modifiedRequestConditions), timeout,
                 context).getValue().getBlobCommittedBlockCount());
         
        Parameters:
        options - options for the operation
        timeout - An optional timeout value beyond which a RuntimeException will be raised.
        context - Additional context that is passed through the Http pipeline during the service call.
        Returns:
        The information of the append blob operation.
      • seal

        public void seal()
        Seals an append blob, making it read only. Any subsequent appends will fail.

        Code Samples

         client.seal();
         System.out.println("Sealed AppendBlob");
         
      • sealWithResponse

        public com.azure.core.http.rest.Response<Void> sealWithResponse​(AppendBlobSealOptions options,
                                                                        Duration timeout,
                                                                        com.azure.core.util.Context context)
        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));
         Context context = new Context("key", "value");
        
         client.sealWithResponse(new AppendBlobSealOptions().setRequestConditions(requestConditions), timeout, context);
         System.out.println("Sealed AppendBlob");
         
        Parameters:
        options - AppendBlobSealOptions
        timeout - An optional timeout value beyond which a RuntimeException will be raised.
        context - Additional context that is passed through the Http pipeline during the service call.
        Returns:
        A reactive response signalling completion.