BlockBlobClient Class
- java.
lang. Object - com.
azure. storage. blob. specialized. BlobClientBase - com.
azure. storage. blob. specialized. BlockBlobClient
- com.
- com.
public final class BlockBlobClient
extends BlobClientBase
Client to a block blob. It may only be instantiated through a SpecializedBlobClientBuilder or via the method getBlockBlobClient(). 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.
Please refer to the Azure Docs for more information.
Field Summary
Modifier and Type | Field and Description |
---|---|
static final int |
MAX_BLOCKS
Indicates the maximum number of blocks allowed in a block blob. |
static final int |
MAX_STAGE_BLOCK_BYTES
Deprecated Indicates the maximum number of bytes that can be sent in a call to stage |
static final long |
MAX_STAGE_BLOCK_BYTES_LONG
Indicates the maximum number of bytes that can be sent in a call to stage |
static final int |
MAX_UPLOAD_BLOB_BYTES
Deprecated Indicates the maximum number of bytes that can be sent in a call to upload. |
static final long |
MAX_UPLOAD_BLOB_BYTES_LONG
Indicates the maximum number of bytes that can be sent in a call to upload. |
Method Summary
Methods inherited from BlobClientBase
Methods inherited from java.lang.Object
Field Details
MAX_BLOCKS
public static final int MAX_BLOCKS
Indicates the maximum number of blocks allowed in a block blob.
MAX_STAGE_BLOCK_BYTES
@Deprecated
public static final int MAX_STAGE_BLOCK_BYTES
Deprecated
Indicates the maximum number of bytes that can be sent in a call to stageBlock.
MAX_STAGE_BLOCK_BYTES_LONG
public static final long MAX_STAGE_BLOCK_BYTES_LONG
Indicates the maximum number of bytes that can be sent in a call to stageBlock.
MAX_UPLOAD_BLOB_BYTES
@Deprecated
public static final int MAX_UPLOAD_BLOB_BYTES
Deprecated
Indicates the maximum number of bytes that can be sent in a call to upload.
MAX_UPLOAD_BLOB_BYTES_LONG
public static final long MAX_UPLOAD_BLOB_BYTES_LONG
Indicates the maximum number of bytes that can be sent in a call to upload.
Method Details
commitBlockList
public BlockBlobItem commitBlockList(List
Writes a blob by specifying the list of block IDs that are to make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior stageBlock operation. You can call commitBlockList to update a blob by uploading only those blocks that have changed, then committing the new and existing blocks together. Any blocks not specified in the block list and permanently deleted. For more information, see the Azure Docs.
Code Samples
System.out.printf("Committing block list completed. Last modified: %s%n",
client.commitBlockList(Collections.singletonList(base64BlockId)).getLastModified());
Parameters:
String
s that specifies the block IDs to be committed.
Returns:
commitBlockList
public BlockBlobItem commitBlockList(List
Writes a blob by specifying the list of block IDs that are to make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior stageBlock operation. You can call commitBlockList to update a blob by uploading only those blocks that have changed, then committing the new and existing blocks together. Any blocks not specified in the block list and permanently deleted. For more information, see the Azure Docs.
Code Samples
boolean overwrite = false; // Default behavior
System.out.printf("Committing block list completed. Last modified: %s%n",
client.commitBlockList(Collections.singletonList(base64BlockId), overwrite).getLastModified());
Parameters:
String
s that specifies the block IDs to be committed.
Returns:
commitBlockListWithResponse
public Response
Writes a blob by specifying the list of block IDs that are to make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior stageBlock operation. You can call commitBlockList to update a blob by uploading only those blocks that have changed, then committing the new and existing blocks together. Any blocks not specified in the block list and permanently deleted. For more information, see the Azure Docs.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5("data".getBytes(StandardCharsets.UTF_8))
.setContentLanguage("en-US")
.setContentType("binary");
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));
Context context = new Context("key", "value");
System.out.printf("Committing block list completed with status %d%n",
client.commitBlockListWithResponse(
new BlockBlobCommitBlockListOptions(Collections.singletonList(base64BlockId)).setHeaders(headers)
.setMetadata(metadata).setTags(tags).setTier(AccessTier.HOT)
.setRequestConditions(requestConditions), timeout, context)
.getStatusCode());
Parameters:
Returns:
commitBlockListWithResponse
public Response
Writes a blob by specifying the list of block IDs that are to make up the blob. In order to be written as part of a blob, a block must have been successfully written to the server in a prior stageBlock operation. You can call commitBlockList to update a blob by uploading only those blocks that have changed, then committing the new and existing blocks together. Any blocks not specified in the block list and permanently deleted. For more information, see the Azure Docs.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5(MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8)))
.setContentLanguage("en-US")
.setContentType("binary");
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("Committing block list completed with status %d%n",
client.commitBlockListWithResponse(Collections.singletonList(base64BlockId), headers, metadata,
AccessTier.HOT, requestConditions, timeout, context).getStatusCode());
Parameters:
String
s that specifies the block IDs to be committed.
Returns:
getBlobOutputStream
public BlobOutputStream getBlobOutputStream()
Creates and opens an output stream to write data to the block blob.
Note: We recommend you call write with reasonably sized buffers, you can do so by wrapping the BlobOutputStream obtained below with a BufferedOutputStream.
Returns:
getBlobOutputStream
public BlobOutputStream getBlobOutputStream(boolean overwrite)
Creates and opens an output stream to write data to the block blob.
Note: We recommend you call write with reasonably sized buffers, you can do so by wrapping the BlobOutputStream obtained below with a BufferedOutputStream.
Parameters:
Returns:
getBlobOutputStream
public BlobOutputStream getBlobOutputStream(BlobRequestConditions requestConditions)
Creates and opens an output stream to write data to the block blob. If the blob already exists on the service, it will be overwritten.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Note: We recommend you call write with reasonably sized buffers, you can do so by wrapping the BlobOutputStream obtained below with a BufferedOutputStream.
Parameters:
Returns:
getBlobOutputStream
public BlobOutputStream getBlobOutputStream(ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map
Creates and opens an output stream to write data to the block blob. If the blob already exists on the service, it will be overwritten.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Note: We recommend you call write with reasonably sized buffers, you can do so by wrapping the BlobOutputStream obtained below with a BufferedOutputStream.
Parameters:
Returns:
getBlobOutputStream
public BlobOutputStream getBlobOutputStream(BlockBlobOutputStreamOptions options)
Creates and opens an output stream to write data to the block blob. If the blob already exists on the service, it will be overwritten.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Note: We recommend you call write with reasonably sized buffers, you can do so by wrapping the BlobOutputStream obtained below with a BufferedOutputStream.
Parameters:
Returns:
getBlobOutputStream
public BlobOutputStream getBlobOutputStream(BlockBlobOutputStreamOptions options, Context context)
Creates and opens an output stream to write data to the block blob. If the blob already exists on the service, it will be overwritten.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Note: We recommend you call write with reasonably sized buffers, you can do so by wrapping the BlobOutputStream obtained below with a BufferedOutputStream.
Parameters:
Returns:
getCustomerProvidedKeyClient
public BlockBlobClient getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)
Creates a new BlockBlobClient with the specified customerProvidedKey
.
Overrides:
BlockBlobClient.getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)Parameters:
null
to use no customer provided key.
Returns:
customerProvidedKey
.getEncryptionScopeClient
public BlockBlobClient getEncryptionScopeClient(String encryptionScope)
Creates a new BlockBlobClient with the specified encryptionScope
.
Overrides:
BlockBlobClient.getEncryptionScopeClient(String encryptionScope)Parameters:
null
to use no encryption scope.
Returns:
encryptionScope
.listBlocks
public BlockList listBlocks(BlockListType listType)
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 Azure Docs.
Code Samples
BlockList block = client.listBlocks(BlockListType.ALL);
System.out.println("Committed Blocks:");
block.getCommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(), b.getSizeLong()));
System.out.println("Uncommitted Blocks:");
block.getUncommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(), b.getSizeLong()));
Parameters:
Returns:
listBlocksWithResponse
public Response
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 Azure Docs.
Code Samples
Context context = new Context("key", "value");
BlockList block = client.listBlocksWithResponse(BlockListType.ALL, leaseId, timeout, context).getValue();
System.out.println("Committed Blocks:");
block.getCommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(), b.getSizeLong()));
System.out.println("Uncommitted Blocks:");
block.getUncommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(), b.getSizeLong()));
Parameters:
Returns:
listBlocksWithResponse
public Response
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 Azure Docs.
Code Samples
Context context = new Context("key", "value");
BlockList block = client.listBlocksWithResponse(new BlockBlobListBlocksOptions(BlockListType.ALL)
.setLeaseId(leaseId)
.setIfTagsMatch(tags), timeout, context).getValue();
System.out.println("Committed Blocks:");
block.getCommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(), b.getSizeLong()));
System.out.println("Uncommitted Blocks:");
block.getUncommittedBlocks().forEach(b -> System.out.printf("Name: %s, Size: %d", b.getName(), b.getSizeLong()));
Parameters:
Returns:
openSeekableByteChannelWrite
public SeekableByteChannel openSeekableByteChannelWrite(BlockBlobSeekableByteChannelWriteOptions options)
Opens a seekable byte channel in write-only mode to upload the blob.
Parameters:
Returns:
SeekableByteChannel
object that represents the channel to use for writing to the blob.stageBlock
public void stageBlock(String base64BlockId, BinaryData data)
Uploads the specified block to the block blob's "staging area" to be later committed by a call to commitBlockList. For more information, see the Azure Docs.
Code Samples
BinaryData binaryData = BinaryData.fromStream(data, length);
client.stageBlock(base64BlockId, binaryData);
Parameters:
String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.
BinaryData
must have defined length
and must be replayable if retries are enabled (the default), see BinaryData#isReplayable().
stageBlock
public void stageBlock(String base64BlockId, InputStream data, long length)
Uploads the specified block to the block blob's "staging area" to be later committed by a call to commitBlockList. For more information, see the Azure Docs.
Code Samples
client.stageBlock(base64BlockId, data, length);
Parameters:
String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.
stageBlockFromUrl
public void stageBlockFromUrl(String base64BlockId, String sourceUrl, BlobRange sourceRange)
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 Azure Docs.
Code Samples
client.stageBlockFromUrl(base64BlockId, sourceUrl, new BlobRange(offset, count));
Parameters:
String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.
stageBlockFromUrlWithResponse
public Response
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 Azure Docs.
Code Samples
BlobRequestConditions sourceRequestConditions = new BlobRequestConditions()
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
Context context = new Context("key", "value");
System.out.printf("Staging block from URL completed with status %d%n",
client.stageBlockFromUrlWithResponse(new BlockBlobStageBlockFromUrlOptions(base64BlockId, sourceUrl)
.setSourceRange(new BlobRange(offset, count)).setLeaseId(leaseId)
.setSourceRequestConditions(sourceRequestConditions), timeout, context).getStatusCode());
Parameters:
Returns:
stageBlockFromUrlWithResponse
public Response
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 Azure Docs.
Code Samples
BlobRequestConditions sourceRequestConditions = new BlobRequestConditions()
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
Context context = new Context("key", "value");
System.out.printf("Staging block from URL completed with status %d%n",
client.stageBlockFromUrlWithResponse(base64BlockId, sourceUrl, new BlobRange(offset, count), null,
leaseId, sourceRequestConditions, timeout, context).getStatusCode());
Parameters:
String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.
Returns:
stageBlockWithResponse
public Response
Uploads the specified block to the block blob's "staging area" to be later committed by a call to commitBlockList. For more information, see the Azure Docs.
Code Samples
Context context = new Context("key", "value");
BinaryData binaryData = BinaryData.fromStream(data, length);
BlockBlobStageBlockOptions options = new BlockBlobStageBlockOptions(base64BlockId, binaryData)
.setContentMd5(md5)
.setLeaseId(leaseId);
System.out.printf("Staging block completed with status %d%n",
client.stageBlockWithResponse(options, timeout, context).getStatusCode());
Parameters:
Returns:
stageBlockWithResponse
public Response
Uploads the specified block to the block blob's "staging area" to be later committed by a call to commitBlockList. For more information, see the Azure Docs.
Code Samples
Context context = new Context("key", "value");
System.out.printf("Staging block completed with status %d%n",
client.stageBlockWithResponse(base64BlockId, data, length, md5, leaseId, timeout, context).getStatusCode());
Parameters:
String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.
Returns:
upload
public BlockBlobItem upload(BinaryData data)
Creates a new block blob. By default, this method will not overwrite an existing blob. Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
Code Samples
BinaryData binaryData = BinaryData.fromStream(data, length);
System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(client.upload(binaryData).getContentMd5()));
Parameters:
BinaryData
must have defined length
and must be replayable if retries are enabled (the default), see BinaryData#isReplayable().
Returns:
upload
public BlockBlobItem upload(BinaryData data, boolean overwrite)
Creates a new block blob, or updates the content of an existing block blob. Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
Code Samples
boolean overwrite = false;
BinaryData binaryData = BinaryData.fromStream(data, length);
System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(client.upload(binaryData, overwrite).getContentMd5()));
Parameters:
BinaryData
must have defined length
and must be replayable if retries are enabled (the default), see BinaryData#isReplayable().
Returns:
upload
public BlockBlobItem upload(InputStream data, long length)
Creates a new block blob. By default, this method will not overwrite an existing blob. Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
Code Samples
System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(client.upload(data, length).getContentMd5()));
Parameters:
Returns:
upload
public BlockBlobItem upload(InputStream data, long length, boolean overwrite)
Creates a new block blob, or updates the content of an existing block blob. Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
Code Samples
boolean overwrite = false;
System.out.printf("Uploaded BlockBlob MD5 is %s%n",
Base64.getEncoder().encodeToString(client.upload(data, length, overwrite).getContentMd5()));
Parameters:
Returns:
uploadFromUrl
public BlockBlobItem uploadFromUrl(String sourceUrl)
Creates a new block blob, or updates the content of an existing block blob.
Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlobFromUrl; the content of the existing blob is overwritten with the new content. For more information, see the Azure Docs.
Code Samples
System.out.printf("Uploaded BlockBlob from URL, MD5 is %s%n",
Base64.getEncoder().encodeToString(client.uploadFromUrl(sourceUrl).getContentMd5()));
Parameters:
Returns:
uploadFromUrl
public BlockBlobItem uploadFromUrl(String sourceUrl, boolean overwrite)
Creates a new block blob, or updates the content of an existing block blob.
Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlobFromUrl; the content of the existing blob is overwritten with the new content. For more information, see the Azure Docs.
Code Samples
boolean overwrite = false;
System.out.printf("Uploaded BlockBlob from URL, MD5 is %s%n",
Base64.getEncoder().encodeToString(client.uploadFromUrl(sourceUrl, overwrite).getContentMd5()));
Parameters:
Returns:
uploadFromUrlWithResponse
public Response
Creates a new block blob, or updates the content of an existing block blob.
Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlobFromUrl; the content of the existing blob is overwritten with the new content. For more information, see the Azure Docs.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5(MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8)))
.setContentLanguage("en-US")
.setContentType("binary");
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
Map<String, String> tags = Collections.singletonMap("tag", "value");
byte[] md5 = MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8));
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
Context context = new Context("key", "value");
System.out.printf("Uploaded BlockBlob MD5 is %s%n", Base64.getEncoder()
.encodeToString(client.uploadFromUrlWithResponse(new BlobUploadFromUrlOptions(sourceUrl)
.setHeaders(headers).setTags(tags).setTier(AccessTier.HOT).setContentMd5(md5)
.setDestinationRequestConditions(requestConditions), timeout, context)
.getValue()
.getContentMd5()));
Parameters:
Returns:
uploadWithResponse
public Response
Creates a new block blob, or updates the content of an existing block blob. Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5(MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8)))
.setContentLanguage("en-US")
.setContentType("binary");
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
Map<String, String> tags = Collections.singletonMap("tag", "value");
byte[] md5 = MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8));
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
Context context = new Context("key", "value");
System.out.printf("Uploaded BlockBlob MD5 is %s%n", Base64.getEncoder()
.encodeToString(client.uploadWithResponse(new BlockBlobSimpleUploadOptions(data, length)
.setHeaders(headers).setMetadata(metadata).setTags(tags).setTier(AccessTier.HOT).setContentMd5(md5)
.setRequestConditions(requestConditions), timeout, context)
.getValue()
.getContentMd5()));
Parameters:
Returns:
uploadWithResponse
public Response
Creates a new block blob, or updates the content of an existing block blob. Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported with PutBlob; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use PutBlock and PutBlockList. For more information, see the Azure Docs.
To avoid overwriting, pass "*" to setIfNoneMatch(String ifNoneMatch).
Code Samples
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5(MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8)))
.setContentLanguage("en-US")
.setContentType("binary");
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
byte[] md5 = MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8));
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
Context context = new Context("key", "value");
System.out.printf("Uploaded BlockBlob MD5 is %s%n", Base64.getEncoder()
.encodeToString(client.uploadWithResponse(data, length, headers, metadata, AccessTier.HOT, md5,
requestConditions, timeout, context)
.getValue()
.getContentMd5()));
Parameters:
Returns: