public class BlobClientBase extends Object
This client offers the ability to download blobs. Note that uploading data is specific to each type of blob. Please
refer to the BlockBlobClient
, PageBlobClient
, or AppendBlobClient
for upload options.
Modifier | Constructor and Description |
---|---|
protected |
BlobClientBase(BlobAsyncClientBase client)
Constructor used by
SpecializedBlobClientBuilder . |
Modifier and Type | Method and Description |
---|---|
void |
abortCopyFromUrl(String copyId)
Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata.
|
Response<Void> |
abortCopyFromUrlWithResponse(String copyId,
String leaseId,
Duration timeout,
Context context)
Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata.
|
SyncPoller<BlobCopyInfo,Void> |
beginCopy(String sourceUrl,
Duration pollInterval)
Copies the data at the source URL to a blob.
|
SyncPoller<BlobCopyInfo,Void> |
beginCopy(String sourceUrl,
Map<String,String> metadata,
AccessTier tier,
RehydratePriority priority,
RequestConditions sourceModifiedAccessConditions,
BlobRequestConditions destAccessConditions,
Duration pollInterval)
Copies the data at the source URL to a blob.
|
String |
copyFromUrl(String copySource)
Copies the data at the source URL to a blob and waits for the copy to complete before returning a response.
|
Response<String> |
copyFromUrlWithResponse(String copySource,
Map<String,String> metadata,
AccessTier tier,
RequestConditions sourceModifiedAccessConditions,
BlobRequestConditions destAccessConditions,
Duration timeout,
Context context)
Copies the data at the source URL to a blob and waits for the copy to complete before returning a response.
|
BlobClientBase |
createSnapshot()
Creates a read-only snapshot of the blob.
|
Response<BlobClientBase> |
createSnapshotWithResponse(Map<String,String> metadata,
BlobRequestConditions accessConditions,
Duration timeout,
Context context)
Creates a read-only snapshot of the blob.
|
void |
delete()
Deletes the specified blob or snapshot.
|
Response<Void> |
deleteWithResponse(DeleteSnapshotsOptionType deleteBlobSnapshotOptions,
BlobRequestConditions accessConditions,
Duration timeout,
Context context)
Deletes the specified blob or snapshot.
|
void |
download(OutputStream stream)
Downloads the entire blob into an output stream.
|
BlobProperties |
downloadToFile(String filePath)
Downloads the entire blob into a file specified by the path.
|
Response<BlobProperties> |
downloadToFileWithResponse(String filePath,
BlobRange range,
ParallelTransferOptions parallelTransferOptions,
DownloadRetryOptions options,
BlobRequestConditions accessConditions,
boolean rangeGetContentMD5,
Duration timeout,
Context context)
Downloads the entire blob into a file specified by the path.
|
BlobDownloadResponse |
downloadWithResponse(OutputStream stream,
BlobRange range,
DownloadRetryOptions options,
BlobRequestConditions accessConditions,
boolean rangeGetContentMD5,
Duration timeout,
Context context)
Downloads a range of bytes from a blob into an output stream.
|
Boolean |
exists()
Gets if the container this client represents exists in the cloud.
|
Response<Boolean> |
existsWithResponse(Duration timeout,
Context context)
Gets if the container this client represents exists in the cloud.
|
StorageAccountInfo |
getAccountInfo()
Returns the sku name and account kind for the account.
|
Response<StorageAccountInfo> |
getAccountInfoWithResponse(Duration timeout,
Context context)
Returns the sku name and account kind for the account.
|
String |
getAccountName()
Get associated account name.
|
String |
getBlobName()
Decodes and gets the blob name.
|
String |
getBlobUrl()
Gets the URL of the blob represented by this client.
|
String |
getContainerName()
Get the container name.
|
CpkInfo |
getCustomerProvidedKey()
Gets the
CpkInfo used to encrypt this blob's content on the server. |
HttpPipeline |
getHttpPipeline()
Gets the
HttpPipeline powering this client. |
BlobProperties |
getProperties()
Returns the blob's metadata and properties.
|
Response<BlobProperties> |
getPropertiesWithResponse(BlobRequestConditions accessConditions,
Duration timeout,
Context context)
Returns the blob's metadata and properties.
|
BlobServiceVersion |
getServiceVersion()
Gets the service version the client is using.
|
BlobClientBase |
getSnapshotClient(String snapshot)
Creates a new
BlobClientBase linked to the snapshot of this blob resource. |
String |
getSnapshotId()
Gets the snapshotId for a blob resource
|
boolean |
isSnapshot()
Determines if a blob is a snapshot
|
BlobInputStream |
openInputStream()
Opens a blob input stream to download the blob.
|
BlobInputStream |
openInputStream(BlobRange range,
BlobRequestConditions accessConditions)
Opens a blob input stream to download the specified range of the blob.
|
void |
setAccessTier(AccessTier tier)
Sets the tier on a blob.
|
Response<Void> |
setAccessTierWithResponse(AccessTier tier,
RehydratePriority priority,
String leaseId,
Duration timeout,
Context context)
Sets the tier on a blob.
|
void |
setHttpHeaders(BlobHttpHeaders headers)
Changes a blob's HTTP header properties.
|
Response<Void> |
setHttpHeadersWithResponse(BlobHttpHeaders headers,
BlobRequestConditions accessConditions,
Duration timeout,
Context context)
Changes a blob's HTTP header properties.
|
void |
setMetadata(Map<String,String> metadata)
Changes a blob's metadata.
|
Response<Void> |
setMetadataWithResponse(Map<String,String> metadata,
BlobRequestConditions accessConditions,
Duration timeout,
Context context)
Changes a blob's metadata.
|
void |
undelete()
Undelete restores the content and metadata of a soft-deleted blob and/or any associated soft-deleted snapshots.
|
Response<Void> |
undeleteWithResponse(Duration timeout,
Context context)
Undelete restores the content and metadata of a soft-deleted blob and/or any associated soft-deleted snapshots.
|
protected BlobClientBase(BlobAsyncClientBase client)
SpecializedBlobClientBuilder
.client
- the async blob clientpublic BlobClientBase getSnapshotClient(String snapshot)
BlobClientBase
linked to the snapshot
of this blob resource.snapshot
- the identifier for a specific snapshot of this blobBlobClientBase
used to interact with the specific snapshot.public String getBlobUrl()
public String getAccountName()
public final String getContainerName()
Code Samples
String
containerName = client.getContainerName();System
.out.println("The name of the blob is " + containerName);
public final String getBlobName()
Code Samples
String
blobName = client.getBlobName();System
.out.println("The name of the blob is " + blobName);
public HttpPipeline getHttpPipeline()
HttpPipeline
powering this client.public CpkInfo getCustomerProvidedKey()
CpkInfo
used to encrypt this blob's content on the server.public BlobServiceVersion getServiceVersion()
public String getSnapshotId()
public boolean isSnapshot()
public final BlobInputStream openInputStream()
InputStream
object that represents the stream to use for reading from the blob.BlobStorageException
- If a storage service error occurred.public final BlobInputStream openInputStream(BlobRange range, BlobRequestConditions accessConditions)
range
- BlobRange
accessConditions
- An BlobRequestConditions
object that represents the access conditions for the
blob.InputStream
object that represents the stream to use for reading from the blob.BlobStorageException
- If a storage service error occurred.public Boolean exists()
Code Samples
System
.out.printf("Exists? %b%n", client.exists());
public Response<Boolean> existsWithResponse(Duration timeout, Context context)
Code Samples
System
.out.printf("Exists? %b%n", client.existsWithResponse(timeout, newContext
(key2, value2)).getValue());
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 SyncPoller<BlobCopyInfo,Void> beginCopy(String sourceUrl, Duration pollInterval)
Code Samples
finalSyncPoller
<BlobCopyInfo
,Void
> poller = client.beginCopy(url,Duration
.ofSeconds(2));PollResponse
<BlobCopyInfo
> pollResponse = poller.poll();System
.out.printf("Copy identifier: %s%n", pollResponse.getValue().getCopyId());
For more information, see the Azure Docs
sourceUrl
- The source URL to copy from. URLs outside of Azure may only be copied to block blobs.pollInterval
- Duration between each poll for the copy status. If none is specified, a default of one second
is used.SyncPoller
to poll the progress of blob copy operation.public SyncPoller<BlobCopyInfo,Void> beginCopy(String sourceUrl, Map<String,String> metadata, AccessTier tier, RehydratePriority priority, RequestConditions sourceModifiedAccessConditions, BlobRequestConditions destAccessConditions, Duration pollInterval)
Code Samples
Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");RequestConditions
modifiedAccessConditions = newRequestConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(7));BlobRequestConditions
blobAccessConditions = newBlobRequestConditions
().setLeaseId(leaseId);SyncPoller
<BlobCopyInfo
,Void
> poller = client.beginCopy(url, metadata,AccessTier
.HOT,RehydratePriority
.STANDARD, modifiedAccessConditions, blobAccessConditions,Duration
.ofSeconds(2));PollResponse
<BlobCopyInfo
> response = poller.waitUntil(LongRunningOperationStatus
.SUCCESSFULLY_COMPLETED);System
.out.printf("Copy identifier: %s%n", response.getValue().getCopyId());
For more information, see the Azure Docs
sourceUrl
- The source URL to copy from. URLs outside of Azure may only be copied to block blobs.metadata
- Metadata to associate with the destination blob.tier
- AccessTier
for the destination blob.priority
- RehydratePriority
for rehydrating the blob.sourceModifiedAccessConditions
- RequestConditions
against the source. Standard HTTP Access
conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions
related to when the blob was changed relative to the given request. The request will fail if the specified
condition is not satisfied.destAccessConditions
- BlobRequestConditions
against the destination.pollInterval
- Duration between each poll for the copy status. If none is specified, a default of one second
is used.SyncPoller
to poll the progress of blob copy operation.public void abortCopyFromUrl(String copyId)
Code Samples
client.abortCopyFromUrl(copyId);
System
.out.println("Aborted copy completed.");
For more information, see the Azure Docs
copyId
- The id of the copy operation to abort.public Response<Void> abortCopyFromUrlWithResponse(String copyId, String leaseId, Duration timeout, Context context)
Code Samples
System
.out.printf("Aborted copy completed with status %d%n", client.abortCopyFromUrlWithResponse(copyId, leaseId, timeout, newContext
(key2, value2)).getStatusCode());
For more information, see the Azure Docs
copyId
- The id of the copy operation to abort.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 String copyFromUrl(String copySource)
Code Samples
System
.out.printf("Copy identifier: %s%n", client.copyFromUrl(url));
For more information, see the Azure Docs
copySource
- The source URL to copy from.IllegalArgumentException
- If copySource
is a malformed URL
.public Response<String> copyFromUrlWithResponse(String copySource, Map<String,String> metadata, AccessTier tier, RequestConditions sourceModifiedAccessConditions, BlobRequestConditions destAccessConditions, Duration timeout, Context context)
Code Samples
Map
<String
,String
> metadata =Collections
.singletonMap("metadata", "value");RequestConditions
modifiedAccessConditions = newRequestConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(7));BlobRequestConditions
blobRequestConditions = newBlobRequestConditions
().setLeaseId(leaseId);System
.out.printf("Copy identifier: %s%n", client.copyFromUrlWithResponse(url, metadata,AccessTier
.HOT, modifiedAccessConditions, blobRequestConditions, timeout, newContext
(key1, value1)).getValue());
For more information, see the Azure Docs
copySource
- The source URL to copy from. URLs outside of Azure may only be copied to block blobs.metadata
- Metadata to associate with the destination blob.tier
- AccessTier
for the destination blob.sourceModifiedAccessConditions
- RequestConditions
against the source. Standard HTTP Access
conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions
related to when the blob was changed relative to the given request. The request will fail if the specified
condition is not satisfied.destAccessConditions
- BlobRequestConditions
against the destination.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 copySource
is a malformed URL
.public void download(OutputStream stream)
BlockBlobClient
,
PageBlobClient
, or AppendBlobClient
.
Code Samples
client.download(newByteArrayOutputStream
());System
.out.println("Download completed.");
For more information, see the Azure Docs
stream
- A non-null OutputStream
instance where the downloaded data will be written.UncheckedIOException
- If an I/O error occurs.NullPointerException
- if stream
is nullpublic BlobDownloadResponse downloadWithResponse(OutputStream stream, BlobRange range, DownloadRetryOptions options, BlobRequestConditions accessConditions, boolean rangeGetContentMD5, Duration timeout, Context context)
BlockBlobClient
, PageBlobClient
, or AppendBlobClient
.
Code Samples
BlobRange
range = newBlobRange
(1024, 2048L);DownloadRetryOptions
options = newDownloadRetryOptions
().setMaxRetryRequests(5);System
.out.printf("Download completed with status %d%n", client.downloadWithResponse(newByteArrayOutputStream
(), range, options, null, false, timeout, newContext
(key2, value2)).getStatusCode());
For more information, see the Azure Docs
stream
- A non-null OutputStream
instance where the downloaded data will be written.range
- BlobRange
options
- DownloadRetryOptions
accessConditions
- BlobRequestConditions
rangeGetContentMD5
- Whether the contentMD5 for the specified blob range should be returned.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.UncheckedIOException
- If an I/O error occurs.NullPointerException
- if stream
is nullpublic BlobProperties downloadToFile(String filePath)
The file will be created and must not exist, if the file already exists a FileAlreadyExistsException
will be thrown.
Uploading data must be done from the BlockBlobClient
, PageBlobClient
, or AppendBlobClient
.
Code Samples
client.downloadToFile(file);
System
.out.println("Completed download to file");
For more information, see the Azure Docs
filePath
- A non-null OutputStream
instance where the downloaded data will be written.UncheckedIOException
- If an I/O error occurspublic Response<BlobProperties> downloadToFileWithResponse(String filePath, BlobRange range, ParallelTransferOptions parallelTransferOptions, DownloadRetryOptions options, BlobRequestConditions accessConditions, boolean rangeGetContentMD5, Duration timeout, Context context)
The file will be created and must not exist, if the file already exists a FileAlreadyExistsException
will be thrown.
Uploading data must be done from the BlockBlobClient
, PageBlobClient
, or AppendBlobClient
.
This method makes an extra HTTP call to get the length of the blob in the beginning. To avoid this extra
call, provide the BlobRange
parameter.
Code Samples
BlobRange
range = newBlobRange
(1024, 2048L);DownloadRetryOptions
options = newDownloadRetryOptions
().setMaxRetryRequests(5); client.downloadToFileWithResponse(file, range, newParallelTransferOptions
(4 *Constants
.MB, null, null), options, null, false, timeout, newContext
(key2, value2));System
.out.println("Completed download to file");
For more information, see the Azure Docs
filePath
- A non-null OutputStream
instance where the downloaded data will be written.range
- BlobRange
parallelTransferOptions
- ParallelTransferOptions
to use to download to file. Number of parallel
transfers parameter is ignored.options
- DownloadRetryOptions
accessConditions
- BlobRequestConditions
rangeGetContentMD5
- Whether the contentMD5 for the specified blob range should be returned.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.UncheckedIOException
- If an I/O error occurs.public void delete()
Code Samples
client.delete();
System
.out.println("Delete completed.");
For more information, see the Azure Docs
public Response<Void> deleteWithResponse(DeleteSnapshotsOptionType deleteBlobSnapshotOptions, BlobRequestConditions accessConditions, Duration timeout, Context context)
Code Samples
System
.out.printf("Delete completed with status %d%n", client.deleteWithResponse(DeleteSnapshotsOptionType
.INCLUDE, null, timeout, newContext
(key1, value1)).getStatusCode());
For more information, see the Azure Docs
deleteBlobSnapshotOptions
- Specifies the behavior for deleting the snapshots on this blob. Include
will delete the base blob and all snapshots. Only
will delete only the snapshots. If a snapshot is being
deleted, you must pass null.accessConditions
- 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 BlobProperties getProperties()
Code Samples
BlobProperties
properties = client.getProperties();System
.out.printf("Type: %s, Size: %d%n", properties.getBlobType(), properties.getBlobSize());
For more information, see the Azure Docs
public Response<BlobProperties> getPropertiesWithResponse(BlobRequestConditions accessConditions, Duration timeout, Context context)
Code Samples
BlobRequestConditions
accessConditions = newBlobRequestConditions
().setLeaseId(leaseId);BlobProperties
properties = client.getPropertiesWithResponse(accessConditions, timeout, newContext
(key2, value2)).getValue();System
.out.printf("Type: %s, Size: %d%n", properties.getBlobType(), properties.getBlobSize());
For more information, see the Azure Docs
accessConditions
- 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 void setHttpHeaders(BlobHttpHeaders headers)
Code Samples
client.setHttpHeaders(newBlobHttpHeaders
() .setContentLanguage("en-US") .setContentType("binary"));System
.out.println("Set HTTP headers completed");
For more information, see the Azure Docs
headers
- BlobHttpHeaders
public Response<Void> setHttpHeadersWithResponse(BlobHttpHeaders headers, BlobRequestConditions accessConditions, Duration timeout, Context context)
Code Samples
BlobRequestConditions
accessConditions = newBlobRequestConditions
().setLeaseId(leaseId);System
.out.printf("Set HTTP headers completed with status %d%n", client.setHttpHeadersWithResponse(newBlobHttpHeaders
() .setContentLanguage("en-US") .setContentType("binary"), accessConditions, timeout, newContext
(key1, value1)) .getStatusCode());
For more information, see the Azure Docs
headers
- BlobHttpHeaders
accessConditions
- 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 void setMetadata(Map<String,String> metadata)
Code Samples
client.setMetadata(Collections
.singletonMap("metadata", "value"));System
.out.println("Set metadata completed");
For more information, see the Azure Docs
metadata
- Metadata to associate with the blob.public Response<Void> setMetadataWithResponse(Map<String,String> metadata, BlobRequestConditions accessConditions, Duration timeout, Context context)
Code Samples
BlobRequestConditions
accessConditions = newBlobRequestConditions
().setLeaseId(leaseId);System
.out.printf("Set metadata completed with status %d%n", client.setMetadataWithResponse(Collections
.singletonMap("metadata", "value"), accessConditions, timeout, newContext
(key1, value1)).getStatusCode());
For more information, see the Azure Docs
metadata
- Metadata to associate with the blob.accessConditions
- 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 BlobClientBase createSnapshot()
Code Samples
System
.out.printf("Identifier for the snapshot is %s%n", client.createSnapshot().getSnapshotId());
For more information, see the Azure Docs
BlobClient
which is used to interact with the created snapshot, use
BlobClientBase.getSnapshotId()
to get the identifier for the snapshot.public Response<BlobClientBase> createSnapshotWithResponse(Map<String,String> metadata, BlobRequestConditions accessConditions, Duration timeout, Context context)
Code Samples
Map
<String
,String
> snapshotMetadata =Collections
.singletonMap("metadata", "value");BlobRequestConditions
accessConditions = newBlobRequestConditions
().setLeaseId(leaseId);System
.out.printf("Identifier for the snapshot is %s%n", client.createSnapshotWithResponse(snapshotMetadata, accessConditions, timeout, newContext
(key1, value1)).getValue());
For more information, see the Azure Docs
metadata
- Metadata to associate with the blob snapshot.accessConditions
- 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.BlobClient
which is used to interact with the created snapshot, use
BlobClientBase.getSnapshotId()
to get the identifier for the snapshot.public void setAccessTier(AccessTier tier)
Code Samples
client.setAccessTier(AccessTier
.HOT);System
.out.println("Set tier completed.");
For more information, see the Azure Docs
tier
- The new tier for the blob.public Response<Void> setAccessTierWithResponse(AccessTier tier, RehydratePriority priority, String leaseId, Duration timeout, Context context)
Code Samples
System
.out.printf("Set tier completed with status code %d%n", client.setAccessTierWithResponse(AccessTier
.HOT,RehydratePriority
.STANDARD, leaseId, timeout, newContext
(key2, value2)).getStatusCode());
For more information, see the Azure Docs
tier
- The new tier for the blob.priority
- Optional priority to set for re-hydrating blobs.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 void undelete()
Code Samples
client.undelete();
System
.out.println("Undelete completed");
For more information, see the Azure Docs
public Response<Void> undeleteWithResponse(Duration timeout, Context context)
Code Samples
System
.out.printf("Undelete completed with status %d%n", client.undeleteWithResponse(timeout, newContext
(key1, value1)).getStatusCode());
For more information, see the Azure Docs
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 StorageAccountInfo getAccountInfo()
Code Samples
StorageAccountInfo
accountInfo = client.getAccountInfo();System
.out.printf("Account Kind: %s, SKU: %s%n", accountInfo.getAccountKind(), accountInfo.getSkuName());
For more information, see the Azure Docs
public Response<StorageAccountInfo> getAccountInfoWithResponse(Duration timeout, Context context)
Code Samples
StorageAccountInfo
accountInfo = client.getAccountInfoWithResponse(timeout, newContext
(key1, value1)).getValue();System
.out.printf("Account Kind: %s, SKU: %s%n", accountInfo.getAccountKind(), accountInfo.getSkuName());
For more information, see the Azure Docs
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.