public final class ShareServiceClient extends Object
Instantiating a Synchronous File Service Client
ShareServiceClient
client = newShareServiceClientBuilder
() .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.
|
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 |
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.
|
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(newListSharesOptions
().setPrefix("azure"),Duration
.ofSeconds(1), newContext
(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(newListSharesOptions
().setIncludeMetadata(true) .setIncludeSnapshots(true),Duration
.ofSeconds(1), newContext
(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 sharestimeout
- 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 properties
public 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), newContext
(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), newContext
(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), newContext
(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), newContext
(key1, value1)).getValue(); properties.getMinuteMetrics().setEnabled(true); properties.getHourMetrics().setEnabled(true);Response
<Void
> response = fileServiceClient.setPropertiesWithResponse(properties,Duration
.ofSeconds(1), newContext
(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 shareShareClient
ShareStorageException
- 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), newContext
(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 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), newContext
(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 = newAccountSasPermission
() .setListPermission(true) .setReadPermission(true);AccountSasResourceType
resourceTypes = newAccountSasResourceType
().setContainer(true);AccountSasService
services = newAccountSasService
().setBlobAccess(true).setFileAccess(true);OffsetDateTime
expiryTime =OffsetDateTime
.now().plus(Duration
.ofDays(2));AccountSasSignatureValues
sasValues = newAccountSasSignatureValues
(expiryTime, permissions, services, resourceTypes); // Client must be authenticated via StorageSharedKeyCredentialString
sas = fileServiceClient.generateAccountSas(sasValues);
accountSasSignatureValues
- AccountSasSignatureValues
String
representing all SAS query parameters.Copyright © 2020 Microsoft Corporation. All rights reserved.