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.
|
com.azure.core.http.rest.Response<Void> |
abortCopyFromUrlWithResponse(String copyId,
String leaseId,
Duration timeout,
com.azure.core.util.Context context)
Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata.
|
com.azure.core.util.polling.SyncPoller<BlobCopyInfo,Void> |
beginCopy(BlobBeginCopyOptions options)
Copies the data at the source URL to a blob.
|
com.azure.core.util.polling.SyncPoller<BlobCopyInfo,Void> |
beginCopy(String sourceUrl,
Duration pollInterval)
Copies the data at the source URL to a blob.
|
com.azure.core.util.polling.SyncPoller<BlobCopyInfo,Void> |
beginCopy(String sourceUrl,
Map<String,String> metadata,
AccessTier tier,
RehydratePriority priority,
com.azure.core.http.RequestConditions sourceModifiedRequestConditions,
BlobRequestConditions destRequestConditions,
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.
|
com.azure.core.http.rest.Response<String> |
copyFromUrlWithResponse(BlobCopyFromUrlOptions options,
Duration timeout,
com.azure.core.util.Context context)
Copies the data at the source URL to a blob and waits for the copy to complete before returning a response.
|
com.azure.core.http.rest.Response<String> |
copyFromUrlWithResponse(String copySource,
Map<String,String> metadata,
AccessTier tier,
com.azure.core.http.RequestConditions sourceModifiedRequestConditions,
BlobRequestConditions destRequestConditions,
Duration timeout,
com.azure.core.util.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.
|
com.azure.core.http.rest.Response<BlobClientBase> |
createSnapshotWithResponse(Map<String,String> metadata,
BlobRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Creates a read-only snapshot of the blob.
|
void |
delete()
Deletes the specified blob or snapshot.
|
com.azure.core.http.rest.Response<Void> |
deleteWithResponse(DeleteSnapshotsOptionType deleteBlobSnapshotOptions,
BlobRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.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.
|
BlobProperties |
downloadToFile(String filePath,
boolean overwrite)
Downloads the entire blob into a file specified by the path.
|
com.azure.core.http.rest.Response<BlobProperties> |
downloadToFileWithResponse(BlobDownloadToFileOptions options,
Duration timeout,
com.azure.core.util.Context context)
Downloads the entire blob into a file specified by the path.
|
com.azure.core.http.rest.Response<BlobProperties> |
downloadToFileWithResponse(String filePath,
BlobRange range,
ParallelTransferOptions parallelTransferOptions,
DownloadRetryOptions downloadRetryOptions,
BlobRequestConditions requestConditions,
boolean rangeGetContentMd5,
Duration timeout,
com.azure.core.util.Context context)
Downloads the entire blob into a file specified by the path.
|
com.azure.core.http.rest.Response<BlobProperties> |
downloadToFileWithResponse(String filePath,
BlobRange range,
ParallelTransferOptions parallelTransferOptions,
DownloadRetryOptions downloadRetryOptions,
BlobRequestConditions requestConditions,
boolean rangeGetContentMd5,
Set<OpenOption> openOptions,
Duration timeout,
com.azure.core.util.Context context)
Downloads the entire blob into a file specified by the path.
|
BlobDownloadResponse |
downloadWithResponse(OutputStream stream,
BlobRange range,
DownloadRetryOptions options,
BlobRequestConditions requestConditions,
boolean getRangeContentMd5,
Duration timeout,
com.azure.core.util.Context context)
Downloads a range of bytes from a blob into an output stream.
|
Boolean |
exists()
Gets if the blob this client represents exists in the cloud.
|
com.azure.core.http.rest.Response<Boolean> |
existsWithResponse(Duration timeout,
com.azure.core.util.Context context)
Gets if the blob this client represents exists in the cloud.
|
String |
generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues)
Generates a service SAS for the blob using the specified
BlobServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential |
String |
generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues,
UserDelegationKey userDelegationKey)
Generates a user delegation SAS for the blob using the specified
BlobServiceSasSignatureValues . |
StorageAccountInfo |
getAccountInfo()
Returns the sku name and account kind for the account.
|
com.azure.core.http.rest.Response<StorageAccountInfo> |
getAccountInfoWithResponse(Duration timeout,
com.azure.core.util.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. |
com.azure.core.http.HttpPipeline |
getHttpPipeline()
Gets the
HttpPipeline powering this client. |
BlobProperties |
getProperties()
Returns the blob's metadata and properties.
|
com.azure.core.http.rest.Response<BlobProperties> |
getPropertiesWithResponse(BlobRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.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
|
Map<String,String> |
getTags()
Returns the blob's tags.
|
com.azure.core.http.rest.Response<Map<String,String>> |
getTagsWithResponse(BlobGetTagsOptions options,
Duration timeout,
com.azure.core.util.Context context)
Returns the blob's tags.
|
BlobClientBase |
getVersionClient(String versionId)
Creates a new
BlobClientBase linked to the version of this blob resource. |
String |
getVersionId()
Gets the versionId 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(BlobInputStreamOptions options)
Opens a blob input stream to download the specified range of the blob.
|
BlobInputStream |
openInputStream(BlobRange range,
BlobRequestConditions requestConditions)
Opens a blob input stream to download the specified range of the blob.
|
InputStream |
openQueryInputStream(String expression)
Opens a blob input stream to query the blob.
|
com.azure.core.http.rest.Response<InputStream> |
openQueryInputStreamWithResponse(BlobQueryOptions queryOptions)
Opens a blob input stream to query the blob.
|
void |
query(OutputStream stream,
String expression)
Queries an entire blob into an output stream.
|
BlobQueryResponse |
queryWithResponse(BlobQueryOptions queryOptions,
Duration timeout,
com.azure.core.util.Context context)
Queries an entire blob into an output stream.
|
void |
setAccessTier(AccessTier tier)
Sets the tier on a blob.
|
com.azure.core.http.rest.Response<Void> |
setAccessTierWithResponse(AccessTier tier,
RehydratePriority priority,
String leaseId,
Duration timeout,
com.azure.core.util.Context context)
Sets the tier on a blob.
|
com.azure.core.http.rest.Response<Void> |
setAccessTierWithResponse(BlobSetAccessTierOptions options,
Duration timeout,
com.azure.core.util.Context context)
Sets the tier on a blob.
|
void |
setHttpHeaders(BlobHttpHeaders headers)
Changes a blob's HTTP header properties.
|
com.azure.core.http.rest.Response<Void> |
setHttpHeadersWithResponse(BlobHttpHeaders headers,
BlobRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Changes a blob's HTTP header properties.
|
void |
setMetadata(Map<String,String> metadata)
Changes a blob's metadata.
|
com.azure.core.http.rest.Response<Void> |
setMetadataWithResponse(Map<String,String> metadata,
BlobRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Changes a blob's metadata.
|
void |
setTags(Map<String,String> tags)
Sets user defined tags.
|
com.azure.core.http.rest.Response<Void> |
setTagsWithResponse(BlobSetTagsOptions options,
Duration timeout,
com.azure.core.util.Context context)
Sets user defined tags.
|
void |
undelete()
Undelete restores the content and metadata of a soft-deleted blob and/or any associated soft-deleted snapshots.
|
com.azure.core.http.rest.Response<Void> |
undeleteWithResponse(Duration timeout,
com.azure.core.util.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 BlobClientBase getVersionClient(String versionId)
BlobClientBase
linked to the version
of this blob resource.versionId
- the identifier for a specific version of this blob,
pass null
to interact with the latest blob version.BlobClientBase
used to interact with the specific version.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 com.azure.core.http.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 String getVersionId()
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 requestConditions)
range
- BlobRange
requestConditions
- 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 BlobInputStream openInputStream(BlobInputStreamOptions options)
options
- BlobInputStreamOptions
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 com.azure.core.http.rest.Response<Boolean> existsWithResponse(Duration timeout, com.azure.core.util.Context context)
Code Samples
System.out.printf("Exists? %b%n", client.existsWithResponse(timeout, new Context(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 com.azure.core.util.polling.SyncPoller<BlobCopyInfo,Void> beginCopy(String sourceUrl, Duration pollInterval)
This method triggers a long-running, asynchronous operations. The source may be another blob or an Azure File. If the source is in another account, the source must either be public or authenticated with a SAS token. If the source is in the same account, the Shared Key authorization on the destination will also be applied to the source. The source URL must be URL encoded.
Code Samples
final SyncPoller<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 com.azure.core.util.polling.SyncPoller<BlobCopyInfo,Void> beginCopy(String sourceUrl, Map<String,String> metadata, AccessTier tier, RehydratePriority priority, com.azure.core.http.RequestConditions sourceModifiedRequestConditions, BlobRequestConditions destRequestConditions, Duration pollInterval)
This method triggers a long-running, asynchronous operations. The source may be another blob or an Azure File. If the source is in another account, the source must either be public or authenticated with a SAS token. If the source is in the same account, the Shared Key authorization on the destination will also be applied to the source. The source URL must be URL encoded.
Code Samples
Map<String, String> metadata = Collections.singletonMap("metadata", "value"); RequestConditions modifiedRequestConditions = new RequestConditions() .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(7)); BlobRequestConditions blobRequestConditions = new BlobRequestConditions().setLeaseId(leaseId); SyncPoller<BlobCopyInfo, Void> poller = client.beginCopy(url, metadata, AccessTier.HOT, RehydratePriority.STANDARD, modifiedRequestConditions, blobRequestConditions, 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.sourceModifiedRequestConditions
- 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.destRequestConditions
- 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 com.azure.core.util.polling.SyncPoller<BlobCopyInfo,Void> beginCopy(BlobBeginCopyOptions options)
This method triggers a long-running, asynchronous operations. The source may be another blob or an Azure File. If the source is in another account, the source must either be public or authenticated with a SAS token. If the source is in the same account, the Shared Key authorization on the destination will also be applied to the source. The source URL must be URL encoded.
Code Samples
Map<String, String> metadata = Collections.singletonMap("metadata", "value"); Map<String, String> tags = Collections.singletonMap("tag", "value"); BlobBeginCopySourceRequestConditions modifiedRequestConditions = new BlobBeginCopySourceRequestConditions() .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(7)); BlobRequestConditions blobRequestConditions = new BlobRequestConditions().setLeaseId(leaseId); SyncPoller<BlobCopyInfo, Void> poller = client.beginCopy(new BlobBeginCopyOptions(url).setMetadata(metadata) .setTags(tags).setTier(AccessTier.HOT).setRehydratePriority(RehydratePriority.STANDARD) .setSourceRequestConditions(modifiedRequestConditions) .setDestinationRequestConditions(blobRequestConditions).setPollInterval(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
options
- BlobBeginCopyOptions
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 com.azure.core.http.rest.Response<Void> abortCopyFromUrlWithResponse(String copyId, String leaseId, Duration timeout, com.azure.core.util.Context context)
Code Samples
System.out.printf("Aborted copy completed with status %d%n", client.abortCopyFromUrlWithResponse(copyId, leaseId, timeout, new Context(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)
The source must be a block blob no larger than 256MB. The source must also be either public or have a sas token attached. The URL must be URL encoded.
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 com.azure.core.http.rest.Response<String> copyFromUrlWithResponse(String copySource, Map<String,String> metadata, AccessTier tier, com.azure.core.http.RequestConditions sourceModifiedRequestConditions, BlobRequestConditions destRequestConditions, Duration timeout, com.azure.core.util.Context context)
The source must be a block blob no larger than 256MB. The source must also be either public or have a sas token attached. The URL must be URL encoded.
Code Samples
Map<String, String> metadata = Collections.singletonMap("metadata", "value"); RequestConditions modifiedRequestConditions = new RequestConditions() .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(7)); BlobRequestConditions blobRequestConditions = new BlobRequestConditions().setLeaseId(leaseId); System.out.printf("Copy identifier: %s%n", client.copyFromUrlWithResponse(url, metadata, AccessTier.HOT, modifiedRequestConditions, blobRequestConditions, timeout, new Context(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.sourceModifiedRequestConditions
- 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.destRequestConditions
- 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 com.azure.core.http.rest.Response<String> copyFromUrlWithResponse(BlobCopyFromUrlOptions options, Duration timeout, com.azure.core.util.Context context)
The source must be a block blob no larger than 256MB. The source must also be either public or have a sas token attached. The URL must be URL encoded.
Code Samples
Map<String, String> metadata = Collections.singletonMap("metadata", "value"); Map<String, String> tags = Collections.singletonMap("tag", "value"); RequestConditions modifiedRequestConditions = new RequestConditions() .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(7)); BlobRequestConditions blobRequestConditions = new BlobRequestConditions().setLeaseId(leaseId); System.out.printf("Copy identifier: %s%n", client.copyFromUrlWithResponse(new BlobCopyFromUrlOptions(url).setMetadata(metadata).setTags(tags) .setTier(AccessTier.HOT).setSourceRequestConditions(modifiedRequestConditions) .setDestinationRequestConditions(blobRequestConditions), timeout, new Context(key1, value1)).getValue());
For more information, see the Azure Docs
options
- BlobCopyFromUrlOptions
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(new ByteArrayOutputStream()); 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 requestConditions, boolean getRangeContentMd5, Duration timeout, com.azure.core.util.Context context)
BlockBlobClient
, PageBlobClient
, or AppendBlobClient
.
Code Samples
BlobRange range = new BlobRange(1024, 2048L); DownloadRetryOptions options = new DownloadRetryOptions().setMaxRetryRequests(5); System.out.printf("Download completed with status %d%n", client.downloadWithResponse(new ByteArrayOutputStream(), range, options, null, false, timeout, new Context(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
requestConditions
- BlobRequestConditions
getRangeContentMd5
- 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.
Code Samples
client.downloadToFile(file); System.out.println("Completed download to file");
For more information, see the Azure Docs
filePath
- A String
representing the filePath where the downloaded data will be written.UncheckedIOException
- If an I/O error occurspublic BlobProperties downloadToFile(String filePath, boolean overwrite)
If overwrite is set to false, the file will be created and must not exist, if the file already exists a
FileAlreadyExistsException
will be thrown.
Code Samples
boolean overwrite = false; // Default value client.downloadToFile(file, overwrite); System.out.println("Completed download to file");
For more information, see the Azure Docs
filePath
- A String
representing the filePath where the downloaded data will be written.overwrite
- Whether or not to overwrite the file, should the file exist.UncheckedIOException
- If an I/O error occurspublic com.azure.core.http.rest.Response<BlobProperties> downloadToFileWithResponse(String filePath, BlobRange range, ParallelTransferOptions parallelTransferOptions, DownloadRetryOptions downloadRetryOptions, BlobRequestConditions requestConditions, boolean rangeGetContentMd5, Duration timeout, com.azure.core.util.Context context)
The file will be created and must not exist, if the file already exists a FileAlreadyExistsException
will be thrown.
Code Samples
BlobRange range = new BlobRange(1024, 2048L); DownloadRetryOptions options = new DownloadRetryOptions().setMaxRetryRequests(5); client.downloadToFileWithResponse(file, range, new ParallelTransferOptions().setBlockSizeLong(4L * Constants.MB), options, null, false, timeout, new Context(key2, value2)); System.out.println("Completed download to file");
For more information, see the Azure Docs
filePath
- A String
representing the filePath where the downloaded data will be written.range
- BlobRange
parallelTransferOptions
- ParallelTransferOptions
to use to download to file. Number of parallel
transfers parameter is ignored.downloadRetryOptions
- DownloadRetryOptions
requestConditions
- 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 com.azure.core.http.rest.Response<BlobProperties> downloadToFileWithResponse(String filePath, BlobRange range, ParallelTransferOptions parallelTransferOptions, DownloadRetryOptions downloadRetryOptions, BlobRequestConditions requestConditions, boolean rangeGetContentMd5, Set<OpenOption> openOptions, Duration timeout, com.azure.core.util.Context context)
By default the file will be created and must not exist, if the file already exists a
FileAlreadyExistsException
will be thrown. To override this behavior, provide appropriate
OpenOptions
Code Samples
BlobRange blobRange = new BlobRange(1024, 2048L); DownloadRetryOptions downloadRetryOptions = new DownloadRetryOptions().setMaxRetryRequests(5); Set<OpenOption> openOptions = new HashSet<>(Arrays.asList(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE, StandardOpenOption.READ)); // Default options client.downloadToFileWithResponse(file, blobRange, new ParallelTransferOptions().setBlockSizeLong(4L * Constants.MB), downloadRetryOptions, null, false, openOptions, timeout, new Context(key2, value2)); System.out.println("Completed download to file");
For more information, see the Azure Docs
filePath
- A String
representing the filePath where the downloaded data will be written.range
- BlobRange
parallelTransferOptions
- ParallelTransferOptions
to use to download to file. Number of parallel
transfers parameter is ignored.downloadRetryOptions
- DownloadRetryOptions
requestConditions
- BlobRequestConditions
rangeGetContentMd5
- Whether the contentMD5 for the specified blob range should be returned.openOptions
- OpenOptions
to use to configure how to open or create the file.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 com.azure.core.http.rest.Response<BlobProperties> downloadToFileWithResponse(BlobDownloadToFileOptions options, Duration timeout, com.azure.core.util.Context context)
By default the file will be created and must not exist, if the file already exists a
FileAlreadyExistsException
will be thrown. To override this behavior, provide appropriate
OpenOptions
Code Samples
client.downloadToFileWithResponse(new BlobDownloadToFileOptions(file) .setRange(new BlobRange(1024, 2018L)) .setDownloadRetryOptions(new DownloadRetryOptions().setMaxRetryRequests(5)) .setOpenOptions(new HashSet<>(Arrays.asList(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE, StandardOpenOption.READ))), timeout, new Context(key2, value2)); System.out.println("Completed download to file");
For more information, see the Azure Docs
options
- BlobDownloadToFileOptions
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 com.azure.core.http.rest.Response<Void> deleteWithResponse(DeleteSnapshotsOptionType deleteBlobSnapshotOptions, BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
Code Samples
System.out.printf("Delete completed with status %d%n", client.deleteWithResponse(DeleteSnapshotsOptionType.INCLUDE, null, timeout, new Context(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.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 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 com.azure.core.http.rest.Response<BlobProperties> getPropertiesWithResponse(BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
Code Samples
BlobRequestConditions requestConditions = new BlobRequestConditions().setLeaseId(leaseId); BlobProperties properties = client.getPropertiesWithResponse(requestConditions, timeout, new Context(key2, value2)).getValue(); System.out.printf("Type: %s, Size: %d%n", properties.getBlobType(), properties.getBlobSize());
For more information, see the Azure Docs
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 void setHttpHeaders(BlobHttpHeaders headers)
Code Samples
client.setHttpHeaders(new BlobHttpHeaders() .setContentLanguage("en-US") .setContentType("binary")); System.out.println("Set HTTP headers completed");
For more information, see the Azure Docs
headers
- BlobHttpHeaders
public com.azure.core.http.rest.Response<Void> setHttpHeadersWithResponse(BlobHttpHeaders headers, BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
Code Samples
BlobRequestConditions requestConditions = new BlobRequestConditions().setLeaseId(leaseId); System.out.printf("Set HTTP headers completed with status %d%n", client.setHttpHeadersWithResponse(new BlobHttpHeaders() .setContentLanguage("en-US") .setContentType("binary"), requestConditions, timeout, new Context(key1, value1)) .getStatusCode());
For more information, see the Azure Docs
headers
- BlobHttpHeaders
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 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 com.azure.core.http.rest.Response<Void> setMetadataWithResponse(Map<String,String> metadata, BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
Code Samples
BlobRequestConditions requestConditions = new BlobRequestConditions().setLeaseId(leaseId); System.out.printf("Set metadata completed with status %d%n", client.setMetadataWithResponse(Collections.singletonMap("metadata", "value"), requestConditions, timeout, new Context(key1, value1)).getStatusCode());
For more information, see the Azure Docs
metadata
- Metadata to associate with the 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 Map<String,String> getTags()
Code Samples
Map<String, String> tags = client.getTags(); System.out.printf("Number of tags: %d%n", tags.size());
For more information, see the Azure Docs
public com.azure.core.http.rest.Response<Map<String,String>> getTagsWithResponse(BlobGetTagsOptions options, Duration timeout, com.azure.core.util.Context context)
Code Samples
Map<String, String> tags = client.getTagsWithResponse(new BlobGetTagsOptions(), timeout, new Context(key1, value1)).getValue(); System.out.printf("Number of tags: %d%n", tags.size());
For more information, see the Azure Docs
options
- BlobGetTagsOptions
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 setTags(Map<String,String> tags)
Code Samples
client.setTags(Collections.singletonMap("tag", "value")); System.out.println("Set tag completed");
For more information, see the Azure Docs
tags
- Tags to associate with the blob.public com.azure.core.http.rest.Response<Void> setTagsWithResponse(BlobSetTagsOptions options, Duration timeout, com.azure.core.util.Context context)
Code Samples
System.out.printf("Set metadata completed with status %d%n", client.setTagsWithResponse(new BlobSetTagsOptions(Collections.singletonMap("tag", "value")), timeout, new Context(key1, value1)) .getStatusCode());
For more information, see the Azure Docs
options
- BlobSetTagsOptions
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
BlobClientBase
which is used to interact with the created snapshot, use
BlobClientBase.getSnapshotId()
to get the identifier for the snapshot.public com.azure.core.http.rest.Response<BlobClientBase> createSnapshotWithResponse(Map<String,String> metadata, BlobRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
Code Samples
Map<String, String> snapshotMetadata = Collections.singletonMap("metadata", "value"); BlobRequestConditions requestConditions = new BlobRequestConditions().setLeaseId(leaseId); System.out.printf("Identifier for the snapshot is %s%n", client.createSnapshotWithResponse(snapshotMetadata, requestConditions, timeout, new Context(key1, value1)).getValue());
For more information, see the Azure Docs
metadata
- Metadata to associate with the blob snapshot.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.BlobClientBase
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 com.azure.core.http.rest.Response<Void> setAccessTierWithResponse(AccessTier tier, RehydratePriority priority, String leaseId, Duration timeout, com.azure.core.util.Context context)
Code Samples
System.out.printf("Set tier completed with status code %d%n", client.setAccessTierWithResponse(AccessTier.HOT, RehydratePriority.STANDARD, leaseId, timeout, new Context(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 com.azure.core.http.rest.Response<Void> setAccessTierWithResponse(BlobSetAccessTierOptions options, Duration timeout, com.azure.core.util.Context context)
Code Samples
System.out.printf("Set tier completed with status code %d%n", client.setAccessTierWithResponse(new BlobSetAccessTierOptions(AccessTier.HOT) .setPriority(RehydratePriority.STANDARD) .setLeaseId(leaseId) .setTagsConditions(tags), timeout, new Context(key2, value2)).getStatusCode());
For more information, see the Azure Docs
options
- BlobSetAccessTierOptions
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 com.azure.core.http.rest.Response<Void> undeleteWithResponse(Duration timeout, com.azure.core.util.Context context)
Code Samples
System.out.printf("Undelete completed with status %d%n", client.undeleteWithResponse(timeout, new Context(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 com.azure.core.http.rest.Response<StorageAccountInfo> getAccountInfoWithResponse(Duration timeout, com.azure.core.util.Context context)
Code Samples
StorageAccountInfo accountInfo = client.getAccountInfoWithResponse(timeout, new Context(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.public String generateUserDelegationSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues, UserDelegationKey userDelegationKey)
BlobServiceSasSignatureValues
.
See BlobServiceSasSignatureValues
for more information on how to construct a user delegation SAS.
Code Samples
OffsetDateTime myExpiryTime = OffsetDateTime.now().plusDays(1); BlobSasPermission myPermission = new BlobSasPermission().setReadPermission(true); BlobServiceSasSignatureValues myValues = new BlobServiceSasSignatureValues(expiryTime, permission) .setStartTime(OffsetDateTime.now()); client.generateUserDelegationSas(values, userDelegationKey);
blobServiceSasSignatureValues
- BlobServiceSasSignatureValues
userDelegationKey
- A UserDelegationKey
object used to sign the SAS values.String
representing all SAS query parameters.for more information on how to get a
user delegation key.
public String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureValues)
BlobServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential
See BlobServiceSasSignatureValues
for more information on how to construct a service SAS.
Code Samples
OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(1); BlobSasPermission permission = new BlobSasPermission().setReadPermission(true); BlobServiceSasSignatureValues values = new BlobServiceSasSignatureValues(expiryTime, permission) .setStartTime(OffsetDateTime.now()); client.generateSas(values); // Client must be authenticated via StorageSharedKeyCredential
blobServiceSasSignatureValues
- BlobServiceSasSignatureValues
String
representing all SAS query parameters.public InputStream openQueryInputStream(String expression)
For more information, see the Azure Docs
Code Samples
String expression = "SELECT * from BlobStorage"; InputStream inputStream = client.openQueryInputStream(expression); // Now you can read from the input stream like you would normally.
expression
- The query expression.InputStream
object that represents the stream to use for reading the query response.public com.azure.core.http.rest.Response<InputStream> openQueryInputStreamWithResponse(BlobQueryOptions queryOptions)
For more information, see the Azure Docs
Code Samples
String expression = "SELECT * from BlobStorage"; BlobQuerySerialization input = new BlobQueryDelimitedSerialization() .setColumnSeparator(',') .setEscapeChar('\n') .setRecordSeparator('\n') .setHeadersPresent(true) .setFieldQuote('"'); BlobQuerySerialization output = new BlobQueryJsonSerialization() .setRecordSeparator('\n'); BlobRequestConditions requestConditions = new BlobRequestConditions() .setLeaseId("leaseId"); Consumer<BlobQueryError> errorConsumer = System.out::println; Consumer<BlobQueryProgress> progressConsumer = progress -> System.out.println("total blob bytes read: " + progress.getBytesScanned()); BlobQueryOptions queryOptions = new BlobQueryOptions(expression) .setInputSerialization(input) .setOutputSerialization(output) .setRequestConditions(requestConditions) .setErrorConsumer(errorConsumer) .setProgressConsumer(progressConsumer); InputStream inputStream = client.openQueryInputStreamWithResponse(queryOptions).getValue(); // Now you can read from the input stream like you would normally.
queryOptions
- The query options
.InputStream
object
that represents the stream to use for reading the query response.public void query(OutputStream stream, String expression)
For more information, see the Azure Docs
Code Samples
ByteArrayOutputStream queryData = new ByteArrayOutputStream(); String expression = "SELECT * from BlobStorage"; client.query(queryData, expression); System.out.println("Query completed.");
stream
- A non-null OutputStream
instance where the downloaded data will be written.expression
- The query expression.UncheckedIOException
- If an I/O error occurs.NullPointerException
- if stream
is null.public BlobQueryResponse queryWithResponse(BlobQueryOptions queryOptions, Duration timeout, com.azure.core.util.Context context)
For more information, see the Azure Docs
Code Samples
ByteArrayOutputStream queryData = new ByteArrayOutputStream(); String expression = "SELECT * from BlobStorage"; BlobQueryJsonSerialization input = new BlobQueryJsonSerialization() .setRecordSeparator('\n'); BlobQueryDelimitedSerialization output = new BlobQueryDelimitedSerialization() .setEscapeChar('\0') .setColumnSeparator(',') .setRecordSeparator('\n') .setFieldQuote('\'') .setHeadersPresent(true); BlobRequestConditions requestConditions = new BlobRequestConditions().setLeaseId(leaseId); Consumer<BlobQueryError> errorConsumer = System.out::println; Consumer<BlobQueryProgress> progressConsumer = progress -> System.out.println("total blob bytes read: " + progress.getBytesScanned()); BlobQueryOptions queryOptions = new BlobQueryOptions(expression, queryData) .setInputSerialization(input) .setOutputSerialization(output) .setRequestConditions(requestConditions) .setErrorConsumer(errorConsumer) .setProgressConsumer(progressConsumer); System.out.printf("Query completed with status %d%n", client.queryWithResponse(queryOptions, timeout, new Context(key1, value1)) .getStatusCode());
queryOptions
- The query 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.UncheckedIOException
- If an I/O error occurs.NullPointerException
- if stream
is null.Copyright © 2020 Microsoft Corporation. All rights reserved.