public final class BlockBlobClient extends BlobClient
BlobClientBuilder
, via the method BlobClient.asBlockBlobClient()
, or via the method ContainerClient.getBlockBlobClient(String)
. 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 ContainerClient
, and
operations on the service are available on BlobServiceClient
.
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
Indicates the maximum number of bytes that can be sent in a call to stageBlock.
|
static int |
MAX_UPLOAD_BLOB_BYTES
Indicates the maximum number of bytes that can be sent in a call to upload.
|
Modifier and Type | Method and Description |
---|---|
BlockBlobItem |
commitBlockList(java.util.List<java.lang.String> base64BlockIDs)
Writes a blob by specifying the list of block IDs that are to make up the blob.
|
Response<BlockBlobItem> |
commitBlockListWithResponse(java.util.List<java.lang.String> base64BlockIDs,
BlobHTTPHeaders headers,
Metadata metadata,
AccessTier tier,
BlobAccessConditions accessConditions,
java.time.Duration timeout,
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(BlobAccessConditions accessConditions)
Creates and opens an output stream to write data to the block blob.
|
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.
|
Response<BlockList> |
listBlocksWithResponse(BlockListType listType,
LeaseAccessConditions leaseAccessConditions,
java.time.Duration timeout,
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(java.lang.String base64BlockID,
java.io.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(java.lang.String base64BlockID,
java.net.URL sourceURL,
BlobRange sourceRange)
Creates a new block to be committed as part of a blob where the contents are read from a URL.
|
VoidResponse |
stageBlockFromURLWithResponse(java.lang.String base64BlockID,
java.net.URL sourceURL,
BlobRange sourceRange,
byte[] sourceContentMD5,
LeaseAccessConditions leaseAccessConditions,
SourceModifiedAccessConditions sourceModifiedAccessConditions,
java.time.Duration timeout,
Context context)
Creates a new block to be committed as part of a blob where the contents are read from a URL.
|
VoidResponse |
stageBlockWithResponse(java.lang.String base64BlockID,
java.io.InputStream data,
long length,
LeaseAccessConditions leaseAccessConditions,
java.time.Duration timeout,
Context context)
Uploads the specified block to the block blob's "staging area" to be later committed by a call to
commitBlockList.
|
BlockBlobItem |
upload(java.io.InputStream data,
long length)
Creates a new block blob, or updates the content of an existing block blob.
|
void |
uploadFromFile(java.lang.String filePath)
Creates a new block blob, or updates the content of an existing block blob.
|
void |
uploadFromFile(java.lang.String filePath,
BlobHTTPHeaders headers,
Metadata metadata,
AccessTier tier,
BlobAccessConditions accessConditions,
java.time.Duration timeout)
Creates a new block blob, or updates the content of an existing block blob.
|
Response<BlockBlobItem> |
uploadWithResponse(java.io.InputStream data,
long length,
BlobHTTPHeaders headers,
Metadata metadata,
AccessTier tier,
BlobAccessConditions accessConditions,
java.time.Duration timeout,
Context context)
Creates a new block blob, or updates the content of an existing block blob.
|
abortCopyFromURL, abortCopyFromURLWithResponse, asAppendBlobClient, asBlockBlobClient, asPageBlobClient, copyFromURL, copyFromURLWithResponse, createSnapshot, createSnapshotWithResponse, delete, deleteWithResponse, download, downloadToFile, downloadToFile, downloadWithResponse, exists, existsWithResponse, generateSAS, generateSAS, generateSAS, generateSAS, generateUserDelegationSAS, generateUserDelegationSAS, generateUserDelegationSAS, getAccountInfo, getAccountInfoWithResponse, getBlobUrl, getContainerClient, getHttpPipeline, getProperties, getPropertiesWithResponse, getSnapshotClient, getSnapshotId, isSnapshot, openInputStream, openInputStream, setHTTPHeaders, setHTTPHeadersWithResponse, setMetadata, setMetadataWithResponse, setTier, setTierWithResponse, startCopyFromURL, startCopyFromURLWithResponse, undelete, undeleteWithResponse
public static final int MAX_UPLOAD_BLOB_BYTES
public static final int MAX_STAGE_BLOCK_BYTES
public static final int MAX_BLOCKS
public BlobOutputStream getBlobOutputStream()
BlobOutputStream
object used to write data to the blob.StorageException
- If a storage service error occurred.public BlobOutputStream getBlobOutputStream(BlobAccessConditions accessConditions)
accessConditions
- A BlobAccessConditions
object that represents the access conditions for the
blob.BlobOutputStream
object used to write data to the blob.StorageException
- If a storage service error occurred.public BlockBlobItem upload(java.io.InputStream data, long length) throws java.io.IOException
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.length
- The exact length of the data. It is important that this value match precisely the length of the
data provided in the InputStream
.java.io.IOException
- If an I/O error occurspublic Response<BlockBlobItem> uploadWithResponse(java.io.InputStream data, long length, BlobHTTPHeaders headers, Metadata metadata, AccessTier tier, BlobAccessConditions accessConditions, java.time.Duration timeout, Context context) throws java.io.IOException
Code Samples
BlobHTTPHeaders
headers = newBlobHTTPHeaders
() .setBlobContentMD5("data".getBytes(StandardCharsets
.UTF_8)) .setBlobContentLanguage("en-US") .setBlobContentType("binary");Metadata
metadata = newMetadata
(Collections
.singletonMap("metadata", "value"));BlobAccessConditions
accessConditions = newBlobAccessConditions
() .setLeaseAccessConditions(newLeaseAccessConditions
().setLeaseId(leaseId)) .setModifiedAccessConditions(newModifiedAccessConditions
() .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, accessConditions, timeout, context) .getValue() .getContentMD5()));
data
- The data to write to the blob.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
tier
- AccessTier
for the destination blob.accessConditions
- BlobAccessConditions
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.UnexpectedLengthException
- when the length of data does not match the input length
.java.lang.NullPointerException
- if the input data is null.java.io.IOException
- If an I/O error occurspublic void uploadFromFile(java.lang.String filePath) throws java.io.IOException
Code Samples
try { client.uploadFromFile(filePath);System
.out.println("Upload from file succeeded"); } catch (UncheckedIOException
ex) {System
.err.printf("Failed to upload from file %s%n", ex.getMessage()); }
filePath
- Path of the file to uploadjava.io.IOException
- If an I/O error occurspublic void uploadFromFile(java.lang.String filePath, BlobHTTPHeaders headers, Metadata metadata, AccessTier tier, BlobAccessConditions accessConditions, java.time.Duration timeout) throws java.io.IOException
Code Samples
BlobHTTPHeaders
headers = newBlobHTTPHeaders
() .setBlobContentMD5("data".getBytes(StandardCharsets
.UTF_8)) .setBlobContentLanguage("en-US") .setBlobContentType("binary");Metadata
metadata = newMetadata
(Collections
.singletonMap("metadata", "value"));BlobAccessConditions
accessConditions = newBlobAccessConditions
() .setLeaseAccessConditions(newLeaseAccessConditions
().setLeaseId(leaseId)) .setModifiedAccessConditions(newModifiedAccessConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3))); try { client.uploadFromFile(filePath, headers, metadata,AccessTier
.HOT, accessConditions, timeout);System
.out.println("Upload from file succeeded"); } catch (UncheckedIOException
ex) {System
.err.printf("Failed to upload from file %s%n", ex.getMessage()); }
filePath
- Path of the file to uploadheaders
- BlobHTTPHeaders
metadata
- Metadata
tier
- AccessTier
for the uploaded blobaccessConditions
- BlobAccessConditions
timeout
- An optional timeout value beyond which a RuntimeException
will be raised.java.io.IOException
- If an I/O error occurspublic void stageBlock(java.lang.String base64BlockID, java.io.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.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 VoidResponse stageBlockWithResponse(java.lang.String base64BlockID, java.io.InputStream data, long length, LeaseAccessConditions leaseAccessConditions, java.time.Duration timeout, Context context)
Code Samples
LeaseAccessConditions
accessConditions = newLeaseAccessConditions
().setLeaseId(leaseId);Context
context = newContext
("key", "value");System
.out.printf("Staging block completed with status %d%n", client.stageBlockWithResponse(base64BlockID, data, length, accessConditions, 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.length
- The exact length of the data. It is important that this value match precisely the length of the
data provided in the InputStream
.leaseAccessConditions
- By setting lease access conditions, requests will fail if the provided lease does
not match the active lease on the blob.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.UnexpectedLengthException
- when the length of data does not match the input length
.java.lang.NullPointerException
- if the input data is null.public void stageBlockFromURL(java.lang.String base64BlockID, java.net.URL 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
public VoidResponse stageBlockFromURLWithResponse(java.lang.String base64BlockID, java.net.URL sourceURL, BlobRange sourceRange, byte[] sourceContentMD5, LeaseAccessConditions leaseAccessConditions, SourceModifiedAccessConditions sourceModifiedAccessConditions, java.time.Duration timeout, Context context)
Code Samples
LeaseAccessConditions
leaseAccessConditions = newLeaseAccessConditions
().setLeaseId(leaseId);SourceModifiedAccessConditions
sourceModifiedAccessConditions = newSourceModifiedAccessConditions
() .setSourceIfUnmodifiedSince(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, leaseAccessConditions, sourceModifiedAccessConditions, 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 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.leaseAccessConditions
- By setting lease access conditions, requests will fail if the provided lease does
not match the active lease on the blob.sourceModifiedAccessConditions
- SourceModifiedAccessConditions
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 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.getSize()));System
.out.println("Uncommitted Blocks:"); block.getUncommittedBlocks().forEach(b ->System
.out.printf("Name: %s, Size: %d", b.getName(), b.getSize()));
listType
- Specifies which type of blocks to return.public Response<BlockList> listBlocksWithResponse(BlockListType listType, LeaseAccessConditions leaseAccessConditions, java.time.Duration timeout, Context context)
Code Samples
LeaseAccessConditions
accessConditions = newLeaseAccessConditions
().setLeaseId(leaseId);Context
context = newContext
("key", "value");BlockList
block = client.listBlocksWithResponse(BlockListType
.ALL, accessConditions, timeout, context).getValue();System
.out.println("Committed Blocks:"); block.getCommittedBlocks().forEach(b ->System
.out.printf("Name: %s, Size: %d", b.getName(), b.getSize()));System
.out.println("Uncommitted Blocks:"); block.getUncommittedBlocks().forEach(b ->System
.out.printf("Name: %s, Size: %d", b.getName(), b.getSize()));
listType
- Specifies which type of blocks to return.leaseAccessConditions
- By setting lease access conditions, requests will fail if the provided lease does
not match the active lease on the blob.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(java.util.List<java.lang.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 Response<BlockBlobItem> commitBlockListWithResponse(java.util.List<java.lang.String> base64BlockIDs, BlobHTTPHeaders headers, Metadata metadata, AccessTier tier, BlobAccessConditions accessConditions, java.time.Duration timeout, Context context)
Code Samples
BlobHTTPHeaders
headers = newBlobHTTPHeaders
() .setBlobContentMD5("data".getBytes(StandardCharsets
.UTF_8)) .setBlobContentLanguage("en-US") .setBlobContentType("binary");Metadata
metadata = newMetadata
(Collections
.singletonMap("metadata", "value"));BlobAccessConditions
accessConditions = newBlobAccessConditions
() .setLeaseAccessConditions(newLeaseAccessConditions
().setLeaseId(leaseId)) .setModifiedAccessConditions(newModifiedAccessConditions
() .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, accessConditions, timeout, context).getStatusCode());
base64BlockIDs
- A list of base64 encode String
s that specifies the block IDs to be committed.headers
- BlobHTTPHeaders
metadata
- Metadata
tier
- AccessTier
for the destination blob.accessConditions
- BlobAccessConditions
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 © 2019 Microsoft Corporation. All rights reserved.