public final class BlockBlobClient extends BlobClientBase
SpecializedBlobClientBuilder
or via the method
BlobClient.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.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_BLOCKS
Indicates the maximum number of blocks allowed in a block blob.
|
static int |
MAX_STAGE_BLOCK_BYTES
Deprecated.
|
static long |
MAX_STAGE_BLOCK_BYTES_LONG
Indicates the maximum number of bytes that can be sent in a call to stageBlock.
|
static int |
MAX_UPLOAD_BLOB_BYTES
Deprecated.
|
static long |
MAX_UPLOAD_BLOB_BYTES_LONG
Indicates the maximum number of bytes that can be sent in a call to upload.
|
Modifier and Type | Method and Description |
---|---|
BlockBlobItem |
commitBlockList(List<String> base64BlockIds)
Writes a blob by specifying the list of block IDs that are to make up the blob.
|
BlockBlobItem |
commitBlockList(List<String> base64BlockIds,
boolean overwrite)
Writes a blob by specifying the list of block IDs that are to make up the blob.
|
com.azure.core.http.rest.Response<BlockBlobItem> |
commitBlockListWithResponse(BlockBlobCommitBlockListOptions options,
Duration timeout,
com.azure.core.util.Context context)
Writes a blob by specifying the list of block IDs that are to make up the blob.
|
com.azure.core.http.rest.Response<BlockBlobItem> |
commitBlockListWithResponse(List<String> base64BlockIds,
BlobHttpHeaders headers,
Map<String,String> metadata,
AccessTier tier,
BlobRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Writes a blob by specifying the list of block IDs that are to make up the blob.
|
BlobOutputStream |
getBlobOutputStream()
Creates and opens an output stream to write data to the block blob.
|
BlobOutputStream |
getBlobOutputStream(BlobRequestConditions requestConditions)
Creates and opens an output stream to write data to the block blob.
|
BlobOutputStream |
getBlobOutputStream(BlockBlobOutputStreamOptions options)
Creates and opens an output stream to write data to the block blob.
|
BlobOutputStream |
getBlobOutputStream(boolean overwrite)
Creates and opens an output stream to write data to the block blob.
|
BlobOutputStream |
getBlobOutputStream(ParallelTransferOptions parallelTransferOptions,
BlobHttpHeaders headers,
Map<String,String> metadata,
AccessTier tier,
BlobRequestConditions requestConditions)
Creates and opens an output stream to write data to the block blob.
|
BlockBlobClient |
getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)
Creates a new
BlockBlobClient with the specified customerProvidedKey . |
BlockBlobClient |
getEncryptionScopeClient(String encryptionScope)
Creates a new
BlockBlobClient with the specified encryptionScope . |
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.
|
com.azure.core.http.rest.Response<BlockList> |
listBlocksWithResponse(BlockBlobListBlocksOptions options,
Duration timeout,
com.azure.core.util.Context context)
Returns the list of blocks that have been uploaded as part of a block blob using the specified block list
filter.
|
com.azure.core.http.rest.Response<BlockList> |
listBlocksWithResponse(BlockListType listType,
String leaseId,
Duration timeout,
com.azure.core.util.Context context)
Returns the list of blocks that have been uploaded as part of a block blob using the specified block list
filter.
|
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.
|
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.
|
com.azure.core.http.rest.Response<Void> |
stageBlockFromUrlWithResponse(String base64BlockId,
String sourceUrl,
BlobRange sourceRange,
byte[] sourceContentMd5,
String leaseId,
BlobRequestConditions sourceRequestConditions,
Duration timeout,
com.azure.core.util.Context context)
Creates a new block to be committed as part of a blob where the contents are read from a URL.
|
com.azure.core.http.rest.Response<Void> |
stageBlockWithResponse(String base64BlockId,
InputStream data,
long length,
byte[] contentMd5,
String leaseId,
Duration timeout,
com.azure.core.util.Context context)
Uploads the specified block to the block blob's "staging area" to be later committed by a call to
commitBlockList.
|
BlockBlobItem |
upload(InputStream data,
long length)
Creates a new block blob.
|
BlockBlobItem |
upload(InputStream data,
long length,
boolean overwrite)
Creates a new block blob, or updates the content of an existing block blob.
|
BlockBlobItem |
uploadFromUrl(String sourceUrl)
Creates a new block blob, or updates the content of an existing block blob.
|
BlockBlobItem |
uploadFromUrl(String sourceUrl,
boolean overwrite)
Creates a new block blob, or updates the content of an existing block blob.
|
com.azure.core.http.rest.Response<BlockBlobItem> |
uploadFromUrlWithResponse(BlobUploadFromUrlOptions options,
Duration timeout,
com.azure.core.util.Context context)
Creates a new block blob, or updates the content of an existing block blob.
|
com.azure.core.http.rest.Response<BlockBlobItem> |
uploadWithResponse(BlockBlobSimpleUploadOptions options,
Duration timeout,
com.azure.core.util.Context context)
Creates a new block blob, or updates the content of an existing block blob.
|
com.azure.core.http.rest.Response<BlockBlobItem> |
uploadWithResponse(InputStream data,
long length,
BlobHttpHeaders headers,
Map<String,String> metadata,
AccessTier tier,
byte[] contentMd5,
BlobRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Creates a new block blob, or updates the content of an existing block blob.
|
abortCopyFromUrl, abortCopyFromUrlWithResponse, beginCopy, beginCopy, beginCopy, copyFromUrl, copyFromUrlWithResponse, copyFromUrlWithResponse, createSnapshot, createSnapshotWithResponse, delete, deleteWithResponse, download, downloadContent, downloadContentWithResponse, downloadStream, downloadStreamWithResponse, downloadToFile, downloadToFile, downloadToFileWithResponse, downloadToFileWithResponse, downloadToFileWithResponse, downloadWithResponse, exists, existsWithResponse, generateSas, generateSas, generateUserDelegationSas, generateUserDelegationSas, getAccountInfo, getAccountInfoWithResponse, getAccountName, getAccountUrl, getBlobName, getBlobUrl, getContainerClient, getContainerName, getCustomerProvidedKey, getHttpPipeline, getProperties, getPropertiesWithResponse, getServiceVersion, getSnapshotClient, getSnapshotId, getTags, getTagsWithResponse, getVersionClient, getVersionId, isSnapshot, openInputStream, openInputStream, openInputStream, openQueryInputStream, openQueryInputStreamWithResponse, query, queryWithResponse, setAccessTier, setAccessTierWithResponse, setAccessTierWithResponse, setHttpHeaders, setHttpHeadersWithResponse, setMetadata, setMetadataWithResponse, setTags, setTagsWithResponse, undelete, undeleteWithResponse
@Deprecated public static final int MAX_UPLOAD_BLOB_BYTES
BlockBlobClient.MAX_STAGE_BLOCK_BYTES_LONG
.public static final long MAX_UPLOAD_BLOB_BYTES_LONG
@Deprecated public static final int MAX_STAGE_BLOCK_BYTES
BlockBlobClient.MAX_STAGE_BLOCK_BYTES_LONG
public static final long MAX_STAGE_BLOCK_BYTES_LONG
public static final int MAX_BLOCKS
public BlockBlobClient getEncryptionScopeClient(String encryptionScope)
BlockBlobClient
with the specified encryptionScope
.getEncryptionScopeClient
in class BlobClientBase
encryptionScope
- the encryption scope for the blob, pass null
to use no encryption scope.BlockBlobClient
with the specified encryptionScope
.public BlockBlobClient getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)
BlockBlobClient
with the specified customerProvidedKey
.getCustomerProvidedKeyClient
in class BlobClientBase
customerProvidedKey
- the CustomerProvidedKey
for the blob,
pass null
to use no customer provided key.BlockBlobClient
with the specified customerProvidedKey
.public BlobOutputStream getBlobOutputStream()
Note: We recommend you call write with reasonably sized buffers, you can do so by wrapping the BlobOutputStream
obtained below with a BufferedOutputStream
.
BlobOutputStream
object used to write data to the blob.BlobStorageException
- If a storage service error occurred.public BlobOutputStream getBlobOutputStream(boolean overwrite)
Note: We recommend you call write with reasonably sized buffers, you can do so by wrapping the BlobOutputStream
obtained below with a BufferedOutputStream
.
overwrite
- Whether or not to overwrite, should data exist on the blob.BlobOutputStream
object used to write data to the blob.BlobStorageException
- If a storage service error occurred.public BlobOutputStream getBlobOutputStream(BlobRequestConditions requestConditions)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
Note: We recommend you call write with reasonably sized buffers, you can do so by wrapping the BlobOutputStream
obtained below with a BufferedOutputStream
.
requestConditions
- A BlobRequestConditions
object that represents the access conditions for the
blob.BlobOutputStream
object used to write data to the blob.BlobStorageException
- If a storage service error occurred.public BlobOutputStream getBlobOutputStream(ParallelTransferOptions parallelTransferOptions, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, BlobRequestConditions requestConditions)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
Note: We recommend you call write with reasonably sized buffers, you can do so by wrapping the BlobOutputStream
obtained below with a BufferedOutputStream
.
parallelTransferOptions
- ParallelTransferOptions
used to configure buffered uploading.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.tier
- AccessTier
for the destination blob.requestConditions
- BlobRequestConditions
BlobOutputStream
object used to write data to the blob.BlobStorageException
- If a storage service error occurred.public BlobOutputStream getBlobOutputStream(BlockBlobOutputStreamOptions options)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
Note: We recommend you call write with reasonably sized buffers, you can do so by wrapping the BlobOutputStream
obtained below with a BufferedOutputStream
.
options
- BlockBlobOutputStreamOptions
BlobOutputStream
object used to write data to the blob.BlobStorageException
- If a storage service error occurred.public BlockBlobItem upload(InputStream data, long length)
Code Samples
System
.out.printf("Uploaded BlockBlob MD5 is %s%n",Base64
.getEncoder().encodeToString(client.upload(data, length).getContentMd5()));
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 BlockBlobClient.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 provided in the InputStream
.UncheckedIOException
- If an I/O error occurspublic BlockBlobItem upload(InputStream data, long length, boolean overwrite)
Code Samples
boolean overwrite = false;System
.out.printf("Uploaded BlockBlob MD5 is %s%n",Base64
.getEncoder().encodeToString(client.upload(data, length, overwrite).getContentMd5()));
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 BlockBlobClient.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 provided in the InputStream
.overwrite
- Whether or not to overwrite, should data exist on the blob.UncheckedIOException
- If an I/O error occurspublic com.azure.core.http.rest.Response<BlockBlobItem> uploadWithResponse(InputStream data, long length, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, byte[] contentMd5, BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
Code Samples
BlobHttpHeaders
headers = newBlobHttpHeaders
() .setContentMd5("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 = newBlobRequestConditions
() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3));Context
context = newContext
("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()));
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 BlockBlobClient.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 provided in the InputStream
.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.tier
- AccessTier
for the destination blob.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.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.com.azure.core.exception.UnexpectedLengthException
- when the length of data does not match the input length
.NullPointerException
- if the input data is null.UncheckedIOException
- If an I/O error occurspublic com.azure.core.http.rest.Response<BlockBlobItem> uploadWithResponse(BlockBlobSimpleUploadOptions options, Duration timeout, com.azure.core.util.Context context)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
Code Samples
BlobHttpHeaders
headers = newBlobHttpHeaders
() .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"); byte[] md5 =MessageDigest
.getInstance("MD5").digest("data".getBytes(StandardCharsets
.UTF_8));BlobRequestConditions
requestConditions = newBlobRequestConditions
() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3));Context
context = newContext
("key", "value");System
.out.printf("Uploaded BlockBlob MD5 is %s%n",Base64
.getEncoder() .encodeToString(client.uploadWithResponse(newBlockBlobSimpleUploadOptions
(data, length) .setHeaders(headers).setMetadata(metadata).setTags(tags).setTier(AccessTier
.HOT).setContentMd5(md5) .setRequestConditions(requestConditions), timeout, context) .getValue() .getContentMd5()));
options
- BlockBlobSimpleUploadOptions
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.com.azure.core.exception.UnexpectedLengthException
- when the length of data does not match the input length
.NullPointerException
- if the input data is null.UncheckedIOException
- If an I/O error occurspublic BlockBlobItem uploadFromUrl(String sourceUrl)
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()));
sourceUrl
- The source URL to upload from.public BlockBlobItem uploadFromUrl(String sourceUrl, boolean overwrite)
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()));
sourceUrl
- The source URL to upload from.overwrite
- Whether or not to overwrite, should data exist on the blob.public com.azure.core.http.rest.Response<BlockBlobItem> uploadFromUrlWithResponse(BlobUploadFromUrlOptions options, Duration timeout, com.azure.core.util.Context context)
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 BlobRequestConditions.setIfNoneMatch(String)
.
Code Samples
BlobHttpHeaders
headers = newBlobHttpHeaders
() .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"); byte[] md5 =MessageDigest
.getInstance("MD5").digest("data".getBytes(StandardCharsets
.UTF_8));BlobRequestConditions
requestConditions = newBlobRequestConditions
() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3));Context
context = newContext
("key", "value");System
.out.printf("Uploaded BlockBlob MD5 is %s%n",Base64
.getEncoder() .encodeToString(client.uploadFromUrlWithResponse(newBlobUploadFromUrlOptions
(sourceUrl) .setHeaders(headers).setTags(tags).setTier(AccessTier
.HOT).setContentMd5(md5) .setDestinationRequestConditions(requestConditions), timeout, context) .getValue() .getContentMd5()));
options
- BlobUploadFromUrlOptions
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.public void stageBlock(String base64BlockId, InputStream data, long length)
Code Samples
client.stageBlock(base64BlockId, data, length);
base64BlockId
- A Base64 encoded String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.data
- The data to write to the block. The data must be markable. This is in order to support retries. If
the data is not markable, consider using BlockBlobClient.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 provided in the InputStream
.public com.azure.core.http.rest.Response<Void> stageBlockWithResponse(String base64BlockId, InputStream data, long length, byte[] contentMd5, String leaseId, Duration timeout, com.azure.core.util.Context context)
Code Samples
Context
context = newContext
("key", "value");System
.out.printf("Staging block completed with status %d%n", client.stageBlockWithResponse(base64BlockId, data, length, md5, leaseId, timeout, context).getStatusCode());
base64BlockId
- A Base64 encoded String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.data
- The data to write to the block. The data must be markable. This is in order to support retries. If
the data is not markable, consider using BlockBlobClient.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 provided in the InputStream
.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.leaseId
- The lease ID the active lease on the blob must match.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.com.azure.core.exception.UnexpectedLengthException
- when the length of data does not match the input length
.NullPointerException
- if the input data is null.public void stageBlockFromUrl(String base64BlockId, String sourceUrl, BlobRange sourceRange)
Code Samples
client.stageBlockFromUrl(base64BlockId, sourceUrl, new BlobRange
(offset, count));
base64BlockId
- A Base64 encoded String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.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
IllegalArgumentException
- If sourceUrl
is a malformed URL
.public com.azure.core.http.rest.Response<Void> stageBlockFromUrlWithResponse(String base64BlockId, String sourceUrl, BlobRange sourceRange, byte[] sourceContentMd5, String leaseId, BlobRequestConditions sourceRequestConditions, Duration timeout, com.azure.core.util.Context context)
Code Samples
BlobRequestConditions
sourceRequestConditions = newBlobRequestConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3));Context
context = newContext
("key", "value");System
.out.printf("Staging block from URL completed with status %d%n", client.stageBlockFromUrlWithResponse(base64BlockId, sourceUrl, newBlobRange
(offset, count), null, leaseId, sourceRequestConditions, timeout, context).getStatusCode());
base64BlockId
- A Base64 encoded String
that specifies the ID for this block. Note that all block
ids for a given blob must be the same length.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. 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.leaseId
- The lease ID that the active lease on the blob must match.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.IllegalArgumentException
- If sourceUrl
is a malformed URL
.public BlockList listBlocks(BlockListType listType)
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()));
listType
- Specifies which type of blocks to return.public com.azure.core.http.rest.Response<BlockList> listBlocksWithResponse(BlockListType listType, String leaseId, Duration timeout, com.azure.core.util.Context context)
Code Samples
Context
context = newContext
("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()));
listType
- Specifies which type of blocks to return.leaseId
- The lease ID the active lease on the blob must match.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.public com.azure.core.http.rest.Response<BlockList> listBlocksWithResponse(BlockBlobListBlocksOptions options, Duration timeout, com.azure.core.util.Context context)
Code Samples
Context
context = newContext
("key", "value");BlockList
block = client.listBlocksWithResponse(newBlockBlobListBlocksOptions
(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()));
options
- BlockBlobListBlocksOptions
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.public BlockBlobItem commitBlockList(List<String> base64BlockIds)
Code Samples
System
.out.printf("Committing block list completed. Last modified: %s%n", client.commitBlockList(Collections
.singletonList(base64BlockId)).getLastModified());
base64BlockIds
- A list of base64 encode String
s that specifies the block IDs to be committed.public BlockBlobItem commitBlockList(List<String> base64BlockIds, boolean overwrite)
Code Samples
boolean overwrite = false; // Default behaviorSystem
.out.printf("Committing block list completed. Last modified: %s%n", client.commitBlockList(Collections
.singletonList(base64BlockId), overwrite).getLastModified());
base64BlockIds
- A list of base64 encode String
s that specifies the block IDs to be committed.overwrite
- Whether or not to overwrite, should data exist on the blob.public com.azure.core.http.rest.Response<BlockBlobItem> commitBlockListWithResponse(List<String> base64BlockIds, BlobHttpHeaders headers, Map<String,String> metadata, AccessTier tier, BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
Code Samples
BlobHttpHeaders
headers = newBlobHttpHeaders
() .setContentMd5("data".getBytes(StandardCharsets
.UTF_8)) .setContentLanguage("en-US") .setContentType("binary");Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");BlobRequestConditions
requestConditions = newBlobRequestConditions
() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3));Context
context = newContext
("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());
base64BlockIds
- A list of base64 encode String
s that specifies the block IDs to be committed.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.tier
- AccessTier
for the destination blob.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.public com.azure.core.http.rest.Response<BlockBlobItem> commitBlockListWithResponse(BlockBlobCommitBlockListOptions options, Duration timeout, com.azure.core.util.Context context)
To avoid overwriting, pass "*" to BlobRequestConditions.setIfNoneMatch(String)
.
Code Samples
BlobHttpHeaders
headers = newBlobHttpHeaders
() .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 = newBlobRequestConditions
() .setLeaseId(leaseId) .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3));Context
context = newContext
("key", "value");System
.out.printf("Committing block list completed with status %d%n", client.commitBlockListWithResponse( newBlockBlobCommitBlockListOptions
(Collections
.singletonList(base64BlockId)).setHeaders(headers) .setMetadata(metadata).setTags(tags).setTier(AccessTier
.HOT) .setRequestConditions(requestConditions), timeout, context) .getStatusCode());
options
- options
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.Copyright © 2021 Microsoft Corporation. All rights reserved.