AppendBlobClient Class
- java.
lang. Object - com.
azure. storage. blob. specialized. BlobClientBase - com.
azure. storage. blob. specialized. AppendBlobClient
- com.
- com.
public final class AppendBlobClient
extends BlobClientBase
Client to an append blob. It may only be instantiated through a SpecializedBlobClientBuilder or via the method getAppendBlobClient(). 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 BlobContainerClient, and operations on the service are available on BlobServiceClient.
Please refer to the Azure Docs for more information.
Field Summary
Modifier and Type | Field and Description |
---|---|
static final int |
MAX_APPEND_BLOCK_BYTES
Deprecated Indicates the maximum number of bytes that can be sent in a call to append |
static final int |
MAX_BLOCKS
Deprecated
use getMaxBlocks().
Indicates the maximum number of blocks allowed in an append blob. |
Method Summary
Methods inherited from BlobClientBase
Methods inherited from java.lang.Object
Field Details
MAX_APPEND_BLOCK_BYTES
@Deprecated
public static final int MAX_APPEND_BLOCK_BYTES
Deprecated
Indicates the maximum number of bytes that can be sent in a call to appendBlock.
MAX_BLOCKS
@Deprecated
public static final int MAX_BLOCKS
Deprecated
Indicates the maximum number of blocks allowed in an append blob.
Method Details
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. For service versions 2022-11-02 and later, the max block size is 100 MB. For previous versions, the max block size is 4 MB. For more information, see the Azure Docs.
Code Samples
System.out.printf("AppendBlob has %d committed blocks%n",
client.appendBlock(data, length).getBlobCommittedBlockCount());
Parameters:
Flux
.
Returns:
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:
Returns:
appendBlockFromUrlWithResponse
public Response
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:
Returns:
appendBlockFromUrlWithResponse
public Response
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:
Returns:
appendBlockWithResponse
public Response
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. For service versions 2022-11-02 and later, the max block size is 100 MB. For previous versions, the max block size is 4 MB. For more information, see the Azure Docs.
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:
Flux
.
Returns:
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:
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:
Returns:
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:
createIfNotExistsWithResponse
public Response
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:
Returns:
createWithResponse
public Response
Creates a 0-length append blob. Call appendBlock to append data to an append blob.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
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:
Returns:
createWithResponse
public Response
Creates a 0-length append blob. Call appendBlock to append data to an append blob.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
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:
Returns:
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, new data will get appended to the existing blob.
Returns:
getBlobOutputStream
public BlobOutputStream getBlobOutputStream(boolean overwrite)
Creates and opens an output stream to write data to the append blob. If overwrite is specified true
, the existing blob will be deleted and recreated, should data exist on the blob. If overwrite is specified false
, new data will get appended to the existing blob.
Parameters:
Returns:
getBlobOutputStream
public BlobOutputStream getBlobOutputStream(AppendBlobRequestConditions requestConditions)
Creates and opens an output stream to write data to the append blob.
Parameters:
Returns:
getCustomerProvidedKeyClient
public AppendBlobClient getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)
Creates a new AppendBlobClient with the specified customerProvidedKey
.
Overrides:
AppendBlobClient.getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)Parameters:
null
to use no customer provided key.
Returns:
customerProvidedKey
.getEncryptionScopeClient
public AppendBlobClient getEncryptionScopeClient(String encryptionScope)
Creates a new AppendBlobClient with the specified encryptionScope
.
Overrides:
AppendBlobClient.getEncryptionScopeClient(String encryptionScope)Parameters:
null
to use no encryption scope.
Returns:
encryptionScope
.getMaxAppendBlockBytes
public int getMaxAppendBlockBytes()
Get the max number of append block bytes based on service version being used. Service versions 2022-11-02 and above support uploading block bytes up to 100MB, all older service versions support up to 4MB.
Returns:
getMaxBlocks
public int getMaxBlocks()
Get the maximum number of blocks allowed in an append blob.
Returns:
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 Response
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:
Returns: