public final class ShareServiceClient extends Object
Instantiating a Synchronous File Service Client
ShareServiceClient client = new ShareServiceClientBuilder()
.connectionString("${connectionString}")
.endpoint("${endpoint}")
.buildClient();
View this for additional ways to construct the shareServiceAsyncClient.
| Modifier and Type | Method and Description |
|---|---|
ShareClient |
createShare(String shareName)
Creates a share in the storage account with the specified name and returns a ShareClient to interact with it.
|
com.azure.core.http.rest.Response<ShareClient> |
createShareWithResponse(String shareName,
Map<String,String> metadata,
Integer quotaInGB,
Duration timeout,
com.azure.core.util.Context context)
Creates a share in the storage account with the specified name and metadata and returns a ShareClient to interact
with it.
|
com.azure.core.http.rest.Response<ShareClient> |
createShareWithResponse(String shareName,
ShareCreateOptions options,
Duration timeout,
com.azure.core.util.Context context)
Creates a share in the storage account with the specified name and options and returns a ShareClient to interact
with it.
|
void |
deleteShare(String shareName)
Deletes the share in the storage account with the given name
|
com.azure.core.http.rest.Response<Void> |
deleteShareWithResponse(String shareName,
String snapshot,
Duration timeout,
com.azure.core.util.Context context)
Deletes the specific snapshot of the share in the storage account with the given name.
|
String |
generateAccountSas(AccountSasSignatureValues accountSasSignatureValues)
Generates an account SAS for the Azure Storage account using the specified
AccountSasSignatureValues. |
String |
generateAccountSas(AccountSasSignatureValues accountSasSignatureValues,
com.azure.core.util.Context context)
Generates an account SAS for the Azure Storage account using the specified
AccountSasSignatureValues. |
String |
getAccountName()
Get associated account name.
|
String |
getFileServiceUrl()
Get the url of the storage file service client.
|
com.azure.core.http.HttpPipeline |
getHttpPipeline()
Gets the
HttpPipeline powering this client. |
ShareServiceProperties |
getProperties()
Retrieves the properties of the storage account's File service.
|
com.azure.core.http.rest.Response<ShareServiceProperties> |
getPropertiesWithResponse(Duration timeout,
com.azure.core.util.Context context)
Retrieves the properties of the storage account's File service.
|
ShareServiceVersion |
getServiceVersion()
Gets the service version the client is using.
|
ShareClient |
getShareClient(String shareName)
Constructs a ShareClient that interacts with the specified share.
|
com.azure.core.http.rest.PagedIterable<ShareItem> |
listShares()
Lists all shares in the storage account without their metadata or snapshots.
|
com.azure.core.http.rest.PagedIterable<ShareItem> |
listShares(ListSharesOptions options,
Duration timeout,
com.azure.core.util.Context context)
Lists the shares in the Storage account that pass the options filter.
|
void |
setProperties(ShareServiceProperties properties)
Sets the properties for the storage account's File service.
|
com.azure.core.http.rest.Response<Void> |
setPropertiesWithResponse(ShareServiceProperties properties,
Duration timeout,
com.azure.core.util.Context context)
Sets the properties for the storage account's File service.
|
ShareClient |
undeleteShare(String deletedShareName,
String deletedShareVersion)
Restores a previously deleted share.
|
com.azure.core.http.rest.Response<ShareClient> |
undeleteShareWithResponse(String deletedShareName,
String deletedShareVersion,
Duration timeout,
com.azure.core.util.Context context)
Restores a previously deleted share.
|
public String getFileServiceUrl()
public ShareServiceVersion getServiceVersion()
public ShareClient getShareClient(String shareName)
If the share doesn't exist in the storage account create in the
shareServiceAsyncClient will
need to be called before interaction with the share can happen.
shareName - Name of the sharepublic com.azure.core.http.rest.PagedIterable<ShareItem> listShares()
Code Samples
List all shares in the account
fileServiceClient.listShares().forEach(
shareItem -> System.out.printf("Share %s exists in the account", shareItem.getName())
);
For more information, see the Azure Docs.
Shares in the storage account without their metadata or snapshotspublic com.azure.core.http.rest.PagedIterable<ShareItem> listShares(ListSharesOptions options, Duration timeout, com.azure.core.util.Context context)
Set starts with name filter using prefix to filter shares that
are
listed.
Pass true to includeMetadata to have metadata returned
for
the shares.
Pass true to includeSnapshots to have snapshots of the
shares listed.
Code Samples
List all shares that begin with "azure"
fileServiceClient.listShares(new ListSharesOptions().setPrefix("azure"), Duration.ofSeconds(1),
new Context(key1, value1)).forEach(
shareItem -> System.out.printf("Share %s exists in the account", shareItem.getName())
);
List all shares including their snapshots and metadata
fileServiceClient.listShares(new ListSharesOptions().setIncludeMetadata(true)
.setIncludeSnapshots(true), Duration.ofSeconds(1), new Context(key1, value1)).forEach(
shareItem -> System.out.printf("Share %s exists in the account", shareItem.getName())
);
For more information, see the Azure Docs.
options - Options for listing shares. If iterating by page, the page size passed to byPage methods such as
ContinuablePagedIterable.iterableByPage(int) will be preferred over the value set on these options.timeout - An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException will be thrown.context - Additional context that is passed through the Http pipeline during the service call.Shares in the storage account that satisfy the filter requirementsRuntimeException - if the operation doesn't complete before the timeout concludes.public ShareServiceProperties getProperties()
Code Samples
Retrieve File service properties
ShareServiceProperties properties = fileServiceClient.getProperties();
System.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b", properties.getHourMetrics().isEnabled(),
properties.getMinuteMetrics().isEnabled());
For more information, see the Azure Docs.
File service propertiespublic com.azure.core.http.rest.Response<ShareServiceProperties> getPropertiesWithResponse(Duration timeout, com.azure.core.util.Context context)
Code Samples
Retrieve File service properties
ShareServiceProperties properties = fileServiceClient.getPropertiesWithResponse(
Duration.ofSeconds(1), new Context(key1, value1)).getValue();
System.out.printf("Hour metrics enabled: %b, Minute metrics enabled: %b", properties.getHourMetrics().isEnabled(),
properties.getMinuteMetrics().isEnabled());
For more information, see the Azure Docs.
timeout - An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException will be thrown.context - Additional context that is passed through the Http pipeline during the service call.File service properties with
headers and response status codeRuntimeException - if the operation doesn't complete before the timeout concludes.public void setProperties(ShareServiceProperties properties)
null value for CORS. To disable all CORS in the Queue service pass an empty list for CORS.
Code Sample
Clear CORS in the File service
ShareServiceProperties properties = fileServiceClient.getProperties();
properties.setCors(Collections.emptyList());
Response<Void> response = fileServiceClient.setPropertiesWithResponse(properties,
Duration.ofSeconds(1), new Context(key1, value1));
System.out.printf("Setting File service properties completed with status code %d", response.getStatusCode());
Enable Minute and Hour Metrics
ShareServiceProperties properties = fileServiceClient.getProperties();
properties.getMinuteMetrics().setEnabled(true);
properties.getHourMetrics().setEnabled(true);
fileServiceClient.setProperties(properties);
System.out.println("Setting File service properties completed.");
For more information, see the Azure Docs.
properties - Storage account File service propertiesShareStorageException - When one of the following is true
allowed headers, exposed headers, or allowed origins exceeds 256 characters.
Allowed methods isn't DELETE, GET, HEAD, MERGE, POST, OPTIONS, or
PUTpublic com.azure.core.http.rest.Response<Void> setPropertiesWithResponse(ShareServiceProperties properties, Duration timeout, com.azure.core.util.Context context)
null value for CORS. To disable all CORS in the Queue service pass an empty list for CORS.
Code Sample
Clear CORS in the File service
ShareServiceProperties properties = fileServiceClient.getProperties();
properties.setCors(Collections.emptyList());
Response<Void> response = fileServiceClient.setPropertiesWithResponse(properties,
Duration.ofSeconds(1), new Context(key1, value1));
System.out.printf("Setting File service properties completed with status code %d", response.getStatusCode());
Enable Minute and Hour Metrics
ShareServiceProperties properties = fileServiceClient.getPropertiesWithResponse(
Duration.ofSeconds(1), new Context(key1, value1)).getValue();
properties.getMinuteMetrics().setEnabled(true);
properties.getHourMetrics().setEnabled(true);
Response<Void> response = fileServiceClient.setPropertiesWithResponse(properties,
Duration.ofSeconds(1), new Context(key1, value1));
System.out.printf("Setting File service properties completed with status code %d", response.getStatusCode());
For more information, see the Azure Docs.
properties - Storage account File service propertiestimeout - An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException will be thrown.context - Additional context that is passed through the Http pipeline during the service call.ShareStorageException - When one of the following is true
allowed headers, exposed headers, or allowed origins exceeds 256 characters.
Allowed methods isn't DELETE, GET, HEAD, MERGE, POST, OPTIONS, or
PUTRuntimeException - if the operation doesn't complete before the timeout concludes.public ShareClient createShare(String shareName)
Code Samples
Create the share with share name of "myshare"
fileServiceClient.createShare("myshare");
System.out.println("Creating the share completed.");
For more information, see the Azure Docs.
shareName - Name of the shareShareClientShareStorageException - If a share with the same name already existspublic com.azure.core.http.rest.Response<ShareClient> createShareWithResponse(String shareName, Map<String,String> metadata, Integer quotaInGB, Duration timeout, com.azure.core.util.Context context)
Code Samples
Create the share "test" with a quota of 10 GB
Response<ShareClient> response = fileServiceClient.createShareWithResponse("test",
Collections.singletonMap("share", "metadata"), null, Duration.ofSeconds(1),
new Context(key1, value1));
System.out.printf("Creating the share completed with status code %d", response.getStatusCode());
For more information, see the Azure Docs.
shareName - Name of the sharemetadata - Optional metadata to associate with the sharequotaInGB - Optional maximum size the share is allowed to grow to in GB. This must be greater than 0 and
less than or equal to 5120. The default value is 5120.timeout - An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException will be thrown.context - Additional context that is passed through the Http pipeline during the service call.ShareClient and the status of creating the share.ShareStorageException - If a share with the same name already exists or quotaInGB is outside the
allowed range.RuntimeException - if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<ShareClient> createShareWithResponse(String shareName, ShareCreateOptions options, Duration timeout, com.azure.core.util.Context context)
Code Samples
Response<ShareClient> response = fileServiceClient.createShareWithResponse("test",
new ShareCreateOptions().setMetadata(Collections.singletonMap("share", "metadata")).setQuotaInGb(1)
.setAccessTier(ShareAccessTier.HOT), Duration.ofSeconds(1), new Context(key1, value1));
System.out.printf("Creating the share completed with status code %d", response.getStatusCode());
For more information, see the Azure Docs.
shareName - Name of the shareoptions - ShareCreateOptionstimeout - An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException will be thrown.context - Additional context that is passed through the Http pipeline during the service call.ShareClient and the status of creating the share.ShareStorageException - If a share with the same name already exists or quotaInGB is outside the
allowed range.RuntimeException - if the operation doesn't complete before the timeout concludes.public void deleteShare(String shareName)
Code Samples
Delete the share "test"
fileServiceClient.deleteShare("myshare");
For more information, see the Azure Docs.
shareName - Name of the shareShareStorageException - If the share doesn't existpublic com.azure.core.http.rest.Response<Void> deleteShareWithResponse(String shareName, String snapshot, Duration timeout, com.azure.core.util.Context context)
Code Samples
Delete the snapshot of share "test" that was created at current time.
OffsetDateTime midnight = OffsetDateTime.of(LocalDateTime.now(), ZoneOffset.UTC);
Response<Void> response = fileServiceClient.deleteShareWithResponse("test", midnight.toString(),
Duration.ofSeconds(1), new Context(key1, value1));
System.out.printf("Deleting the snapshot completed with status code %d", response.getStatusCode());
For more information, see the Azure Docs.
shareName - Name of the sharesnapshot - Identifier of the snapshottimeout - An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException will be thrown.context - Additional context that is passed through the Http pipeline during the service call.ShareStorageException - If the share doesn't exist or the snapshot doesn't existRuntimeException - if the operation doesn't complete before the timeout concludes.public String getAccountName()
public com.azure.core.http.HttpPipeline getHttpPipeline()
HttpPipeline powering this client.public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues)
AccountSasSignatureValues.
Note : The client must be authenticated via StorageSharedKeyCredential
See AccountSasSignatureValues for more information on how to construct an account SAS.
Generating an account SAS
The snippet below generates an AccountSasSignatureValues object that lasts for two days and gives the user read and list access to blob and file shares.
AccountSasPermission permissions = new AccountSasPermission()
.setListPermission(true)
.setReadPermission(true);
AccountSasResourceType resourceTypes = new AccountSasResourceType().setContainer(true);
AccountSasService services = new AccountSasService().setBlobAccess(true).setFileAccess(true);
OffsetDateTime expiryTime = OffsetDateTime.now().plus(Duration.ofDays(2));
AccountSasSignatureValues sasValues =
new AccountSasSignatureValues(expiryTime, permissions, services, resourceTypes);
// Client must be authenticated via StorageSharedKeyCredential
String sas = fileServiceClient.generateAccountSas(sasValues);
accountSasSignatureValues - AccountSasSignatureValuesString representing the SAS query parameters.public String generateAccountSas(AccountSasSignatureValues accountSasSignatureValues, com.azure.core.util.Context context)
AccountSasSignatureValues.
Note : The client must be authenticated via StorageSharedKeyCredential
See AccountSasSignatureValues for more information on how to construct an account SAS.
The snippet below generates a SAS that lasts for two days and gives the user read and list access to blob containers and file shares.
AccountSasPermission permissions = new AccountSasPermission()
.setListPermission(true)
.setReadPermission(true);
AccountSasResourceType resourceTypes = new AccountSasResourceType().setContainer(true);
AccountSasService services = new AccountSasService().setBlobAccess(true).setFileAccess(true);
OffsetDateTime expiryTime = OffsetDateTime.now().plus(Duration.ofDays(2));
AccountSasSignatureValues sasValues =
new AccountSasSignatureValues(expiryTime, permissions, services, resourceTypes);
// Client must be authenticated via StorageSharedKeyCredential
String sas = fileServiceClient.generateAccountSas(sasValues, new Context("key", "value"));
accountSasSignatureValues - AccountSasSignatureValuescontext - Additional context that is passed through the code when generating a SAS.String representing the SAS query parameters.public ShareClient undeleteShare(String deletedShareName, String deletedShareVersion)
If the share associated with provided deletedShareName
already exists, this call will result in a 409 (conflict).
This API is only functional if Share Soft Delete is enabled for the storage account associated with the share. For more information, see the Azure Docs.
Code Samples
ListSharesOptions listSharesOptions = new ListSharesOptions();
listSharesOptions.setIncludeDeleted(true);
fileServiceClient.listShares(listSharesOptions, Duration.ofSeconds(1), context).forEach(
deletedShare -> {
ShareClient shareClient = fileServiceClient.undeleteShare(
deletedShare.getName(), deletedShare.getVersion());
}
);
deletedShareName - The name of the previously deleted share.deletedShareVersion - The version of the previously deleted share.ShareClient used
to interact with the restored share.public com.azure.core.http.rest.Response<ShareClient> undeleteShareWithResponse(String deletedShareName, String deletedShareVersion, Duration timeout, com.azure.core.util.Context context)
If the share associated with provided deletedShareName
already exists, this call will result in a 409 (conflict).
This API is only functional if Share Soft Delete is enabled for the storage account associated with the share. For more information, see the Azure Docs.
Code Samples
ListSharesOptions listSharesOptions = new ListSharesOptions();
listSharesOptions.setIncludeDeleted(true);
fileServiceClient.listShares(listSharesOptions, Duration.ofSeconds(1), context).forEach(
deletedShare -> {
ShareClient shareClient = fileServiceClient.undeleteShareWithResponse(
deletedShare.getName(), deletedShare.getVersion(), Duration.ofSeconds(1), context).getValue();
}
);
deletedShareName - The name of the previously deleted share.deletedShareVersion - The version of the previously deleted share.timeout - An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException will be thrown.context - Additional context that is passed through the Http pipeline during the service call.Response whose value contains the ShareClient used
to interact with the restored share.Copyright © 2021 Microsoft Corporation. All rights reserved.