public class ShareDirectoryClient extends Object
Instantiating an Synchronous Directory Client
ShareDirectoryClient
client = newShareFileClientBuilder
() .connectionString("${connectionString}") .endpoint("${endpoint}") .buildDirectoryClient();
View this
for additional ways to construct the client.
Modifier and Type | Method and Description |
---|---|
ShareDirectoryInfo |
create()
Creates a directory in the file share and returns a response of
ShareDirectoryInfo to interact with it. |
ShareFileClient |
createFile(String fileName,
long maxSize)
Creates a file in this directory with specific name, max number of results and returns a response of
ShareDirectoryInfo to interact with it.
|
com.azure.core.http.rest.Response<ShareFileClient> |
createFileWithResponse(String fileName,
long maxSize,
ShareFileHttpHeaders httpHeaders,
FileSmbProperties smbProperties,
String filePermission,
Map<String,String> metadata,
Duration timeout,
com.azure.core.util.Context context)
Creates a file in this directory with specific name and returns a response of ShareDirectoryInfo to
interact with it.
|
com.azure.core.http.rest.Response<ShareFileClient> |
createFileWithResponse(String fileName,
long maxSize,
ShareFileHttpHeaders httpHeaders,
FileSmbProperties smbProperties,
String filePermission,
Map<String,String> metadata,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Creates a file in this directory with specific name and returns a response of ShareDirectoryInfo to
interact with it.
|
ShareDirectoryClient |
createSubdirectory(String subdirectoryName)
Creates a subdirectory under current directory with specific name and returns a response of ShareDirectoryClient
to interact with it.
|
com.azure.core.http.rest.Response<ShareDirectoryClient> |
createSubdirectoryWithResponse(String subdirectoryName,
FileSmbProperties smbProperties,
String filePermission,
Map<String,String> metadata,
Duration timeout,
com.azure.core.util.Context context)
Creates a subdirectory under current directory with specific name , metadata and returns a response of
ShareDirectoryClient to interact with it.
|
com.azure.core.http.rest.Response<ShareDirectoryInfo> |
createWithResponse(FileSmbProperties smbProperties,
String filePermission,
Map<String,String> metadata,
Duration timeout,
com.azure.core.util.Context context)
Creates a directory in the file share and returns a response of ShareDirectoryInfo to interact with it.
|
void |
delete()
Deletes the directory in the file share.
|
void |
deleteFile(String fileName)
Deletes the file with specific name in this directory.
|
com.azure.core.http.rest.Response<Void> |
deleteFileWithResponse(String fileName,
Duration timeout,
com.azure.core.util.Context context)
Deletes the file with specific name in this directory.
|
com.azure.core.http.rest.Response<Void> |
deleteFileWithResponse(String fileName,
ShareRequestConditions requestConditions,
Duration timeout,
com.azure.core.util.Context context)
Deletes the file with specific name in this directory.
|
void |
deleteSubdirectory(String subdirectoryName)
Deletes the subdirectory with specific name in this directory.
|
com.azure.core.http.rest.Response<Void> |
deleteSubdirectoryWithResponse(String subdirectoryName,
Duration timeout,
com.azure.core.util.Context context)
Deletes the subdirectory with specific name in this directory.
|
com.azure.core.http.rest.Response<Void> |
deleteWithResponse(Duration timeout,
com.azure.core.util.Context context)
Deletes the directory in the file share.
|
CloseHandlesInfo |
forceCloseAllHandles(boolean recursive,
Duration timeout,
com.azure.core.util.Context context)
Closes all handles opened on the directory at the service.
|
CloseHandlesInfo |
forceCloseHandle(String handleId)
Closes a handle on the directory at the service.
|
com.azure.core.http.rest.Response<CloseHandlesInfo> |
forceCloseHandleWithResponse(String handleId,
Duration timeout,
com.azure.core.util.Context context)
Closes a handle on the directory at the service.
|
String |
generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues)
Generates a service SAS for the directory using the specified
ShareServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential |
String |
getAccountName()
Get associated account name.
|
String |
getDirectoryPath()
Get the directory path of the client.
|
String |
getDirectoryUrl()
Get the url of the storage directory client.
|
ShareFileClient |
getFileClient(String fileName)
Constructs a ShareFileClient that interacts with the specified file.
|
com.azure.core.http.HttpPipeline |
getHttpPipeline()
Gets the
HttpPipeline powering this client. |
ShareDirectoryProperties |
getProperties()
Retrieves the properties of this directory.
|
com.azure.core.http.rest.Response<ShareDirectoryProperties> |
getPropertiesWithResponse(Duration timeout,
com.azure.core.util.Context context)
Retrieves the properties of this directory.
|
ShareServiceVersion |
getServiceVersion()
Gets the service version the client is using.
|
String |
getShareName()
Get the share name of directory client.
|
String |
getShareSnapshotId()
Get snapshot id which attached to
ShareDirectoryClient . |
ShareDirectoryClient |
getSubdirectoryClient(String subdirectoryName)
Constructs a ShareDirectoryClient that interacts with the specified directory.
|
com.azure.core.http.rest.PagedIterable<ShareFileItem> |
listFilesAndDirectories()
Lists all sub-directories and files in this directory without their prefix or maxResult in single page.
|
com.azure.core.http.rest.PagedIterable<ShareFileItem> |
listFilesAndDirectories(String prefix,
Integer maxResultsPerPage,
Duration timeout,
com.azure.core.util.Context context)
Lists all sub-directories and files in this directory with their prefix or snapshots.
|
com.azure.core.http.rest.PagedIterable<HandleItem> |
listHandles(Integer maxResultsPerPage,
boolean recursive,
Duration timeout,
com.azure.core.util.Context context)
List of open handles on a directory or a file.
|
ShareDirectorySetMetadataInfo |
setMetadata(Map<String,String> metadata)
Sets the user-defined metadata to associate to the directory.
|
com.azure.core.http.rest.Response<ShareDirectorySetMetadataInfo> |
setMetadataWithResponse(Map<String,String> metadata,
Duration timeout,
com.azure.core.util.Context context)
Sets the user-defined metadata to associate to the directory.
|
ShareDirectoryInfo |
setProperties(FileSmbProperties smbProperties,
String filePermission)
Sets the properties of this directory.
|
com.azure.core.http.rest.Response<ShareDirectoryInfo> |
setPropertiesWithResponse(FileSmbProperties smbProperties,
String filePermission,
Duration timeout,
com.azure.core.util.Context context)
Sets the properties of this directory.
|
public String getDirectoryUrl()
public ShareServiceVersion getServiceVersion()
public ShareFileClient getFileClient(String fileName)
If the file doesn't exist in this directory ShareFileClient.create(long)
create} in the client will
need to be called before interaction with the file can happen.
fileName
- Name of the filepublic ShareDirectoryClient getSubdirectoryClient(String subdirectoryName)
If the file doesn't exist in this directory ShareDirectoryClient.create()
create} in the client will
need to be called before interaction with the directory can happen.
subdirectoryName
- Name of the directorypublic ShareDirectoryInfo create()
ShareDirectoryInfo
to interact with it.
Code Samples
Create the directory
shareDirectoryClient.create();
System
.out.println("Completed creating the directory. ");
For more information, see the Azure Docs.
directory info
.ShareStorageException
- If the directory has already existed, the parent directory does not exist or
directory name is an invalid resource name.public com.azure.core.http.rest.Response<ShareDirectoryInfo> createWithResponse(FileSmbProperties smbProperties, String filePermission, Map<String,String> metadata, Duration timeout, com.azure.core.util.Context context)
Code Samples
Create the directory
FileSmbProperties
smbProperties = newFileSmbProperties
();String
filePermission = "filePermission";Response
<ShareDirectoryInfo
> response = shareDirectoryClient.createWithResponse(smbProperties, filePermission,Collections
.singletonMap("directory", "metadata"),Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.println("Completed creating the directory with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
smbProperties
- The SMB properties of the directory.filePermission
- The file permission of the directory.metadata
- Optional metadata to associate with the directory.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.ShareStorageException
- If the directory has already existed, the parent directory does not exist or
directory name is an invalid resource name.RuntimeException
- if the operation doesn't complete before the timeout concludes.public void delete()
Code Samples
Delete the directory
shareDirectoryClient.delete();
System
.out.println("Completed deleting the file.");
For more information, see the Azure Docs.
ShareStorageException
- If the share doesn't existpublic com.azure.core.http.rest.Response<Void> deleteWithResponse(Duration timeout, com.azure.core.util.Context context)
Code Samples
Delete the directory
Response
<Void
> response = shareDirectoryClient.deleteWithResponse(Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.println("Completed deleting the file with status code: " + response.getStatusCode());
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.ShareStorageException
- If the share doesn't existRuntimeException
- if the operation doesn't complete before the timeout concludes.public ShareDirectoryProperties getProperties()
Code Samples
Retrieve directory properties
ShareDirectoryProperties
response = shareDirectoryClient.getProperties();System
.out.printf("Directory latest modified date is %s.", response.getLastModified());
For more information, see the Azure Docs.
public com.azure.core.http.rest.Response<ShareDirectoryProperties> getPropertiesWithResponse(Duration timeout, com.azure.core.util.Context context)
Code Samples
Retrieve directory properties
Response
<ShareDirectoryProperties
> response = shareDirectoryClient.getPropertiesWithResponse(Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.printf("Directory latest modified date is %s.", response.getValue().getLastModified());
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.RuntimeException
- if the operation doesn't complete before the timeout concludes.public ShareDirectoryInfo setProperties(FileSmbProperties smbProperties, String filePermission)
Code Samples
Set directory properties
FileSmbProperties
smbProperties = newFileSmbProperties
();String
filePermission = "filePermission";ShareDirectoryInfo
response = shareDirectoryClient.setProperties(smbProperties, filePermission);System
.out.printf("Directory latest modified date is %s.", response.getLastModified());
For more information, see the Azure Docs.
smbProperties
- The SMB properties of the directory.filePermission
- The file permission of the directory.public com.azure.core.http.rest.Response<ShareDirectoryInfo> setPropertiesWithResponse(FileSmbProperties smbProperties, String filePermission, Duration timeout, com.azure.core.util.Context context)
Code Samples
Set directory properties
FileSmbProperties
smbProperties = newFileSmbProperties
();String
filePermission = "filePermission";Response
<ShareDirectoryInfo
> response = shareDirectoryClient.setPropertiesWithResponse(smbProperties, filePermission,Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.printf("Directory latest modified date is %s.", response.getValue().getLastModified());
For more information, see the Azure Docs.
smbProperties
- The SMB properties of the directory.filePermission
- The file permission of the directory.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.public ShareDirectorySetMetadataInfo setMetadata(Map<String,String> metadata)
If null
is passed for the metadata it will clear the metadata associated to the directory.
Code Samples
Set the metadata to "directory:updatedMetadata"
ShareDirectorySetMetadataInfo
response = shareDirectoryClient.setMetadata(Collections
.singletonMap("directory", "updatedMetadata"));System
.out.printf("Setting the directory metadata completed with updated etag %s", response.getETag());
Clear the metadata of the directory
ShareDirectorySetMetadataInfo
response = shareDirectoryClient.setMetadata(null);System
.out.printf("Cleared metadata.");
For more information, see the Azure Docs.
metadata
- Optional metadata to set on the directory, if null is passed the metadata for the directory is
clearedShareStorageException
- If the directory doesn't exist or the metadata contains invalid keyspublic com.azure.core.http.rest.Response<ShareDirectorySetMetadataInfo> setMetadataWithResponse(Map<String,String> metadata, Duration timeout, com.azure.core.util.Context context)
If null
is passed for the metadata it will clear the metadata associated to the directory.
Code Samples
Set the metadata to "directory:updatedMetadata"
Response
<ShareDirectorySetMetadataInfo
> response = shareDirectoryClient.setMetadataWithResponse(Collections
.singletonMap("directory", "updatedMetadata"),Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.printf("Setting the directory metadata completed with updated etag %d", response.getStatusCode());
Clear the metadata of the directory
Response
<ShareDirectorySetMetadataInfo
> response = shareDirectoryClient.setMetadataWithResponse(null,Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.printf("Directory latest modified date is %s.", response.getStatusCode());
For more information, see the Azure Docs.
metadata
- Optional metadata to set on the directory, if null is passed the metadata for the directory is
clearedtimeout
- 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 directory doesn't exist or the metadata contains invalid keysRuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.PagedIterable<ShareFileItem> listFilesAndDirectories()
Code Samples
List all sub-directories and files in the account
shareDirectoryClient.listFilesAndDirectories().forEach(
fileRef -> System
.out.printf("Is the resource a directory? %b. The resource name is: %s.",
fileRef.isDirectory(), fileRef.getName())
);
For more information, see the Azure Docs.
File info
in the storage directorypublic com.azure.core.http.rest.PagedIterable<ShareFileItem> listFilesAndDirectories(String prefix, Integer maxResultsPerPage, Duration timeout, com.azure.core.util.Context context)
Code Samples
List all sub-directories and files in this directory with "subdir" prefix and return 10 results in the account
shareDirectoryClient.listFilesAndDirectories("subdir", 10,Duration
.ofSeconds(1), newContext
(key1, value1)).forEach( fileRef ->System
.out.printf("Is the resource a directory? %b. The resource name is: %s.", fileRef.isDirectory(), fileRef.getName()) );
For more information, see the Azure Docs.
prefix
- Optional prefix which filters the results to return only files and directories whose name begins
with.maxResultsPerPage
- Optional maximum number of files and/or directories to return per page.
If the request does not specify maxResultsPerPage or specifies a value greater than 5,000,
the server will return up to 5,000 items.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 info
in this directory with prefix and max number of return results.RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.PagedIterable<HandleItem> listHandles(Integer maxResultsPerPage, boolean recursive, Duration timeout, com.azure.core.util.Context context)
Code Samples
Get 10 handles with recursive call.
Iterable
<HandleItem
> result = shareDirectoryClient.listHandles(10, true,Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.printf("Get handles completed with handle id %s", result.iterator().next().getHandleId());
For more information, see the Azure Docs.
maxResultsPerPage
- Optional maximum number of results will return per pagerecursive
- Specifies operation should apply to the directory specified in the URI, its files, its
subdirectories and their files.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.handles
in the directory that satisfy the requirementsRuntimeException
- if the operation doesn't complete before the timeout concludes.public CloseHandlesInfo forceCloseHandle(String handleId)
ShareDirectoryClient.listHandles(Integer, boolean, Duration, Context)
.
Code Samples
Force close handles returned by list handles.
shareDirectoryClient.listHandles(null, true,Duration
.ofSeconds(30),Context
.NONE).forEach(handleItem -> { shareDirectoryClient.forceCloseHandle(handleItem.getHandleId());System
.out.printf("Closed handle %s on resource %s%n", handleItem.getHandleId(), handleItem.getPath()); });
For more information, see the Azure Docs.
handleId
- Handle ID to be closed.public com.azure.core.http.rest.Response<CloseHandlesInfo> forceCloseHandleWithResponse(String handleId, Duration timeout, com.azure.core.util.Context context)
ShareDirectoryClient.listHandles(Integer, boolean, Duration, Context)
.
Code Samples
Force close handles returned by list handles.
shareDirectoryClient.listHandles(null, true,Duration
.ofSeconds(30),Context
.NONE).forEach(handleItem -> {Response
<CloseHandlesInfo
> closeResponse = shareDirectoryClient.forceCloseHandleWithResponse( handleItem.getHandleId(),Duration
.ofSeconds(30),Context
.NONE);System
.out.printf("Closing handle %s on resource %s completed with status code %d%n", handleItem.getHandleId(), handleItem.getPath(), closeResponse.getStatusCode()); });
For more information, see the Azure Docs.
handleId
- Handle ID to be clsoed.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.public CloseHandlesInfo forceCloseAllHandles(boolean recursive, Duration timeout, com.azure.core.util.Context context)
Code Samples
Force close all handles recursively.
CloseHandlesInfo
closeHandlesInfo = shareDirectoryClient.forceCloseAllHandles(true,Duration
.ofSeconds(30),Context
.NONE);System
.out.printf("Closed %d open handles on the directory%n", closeHandlesInfo.getClosedHandles());System
.out.printf("Failed to close %d open handles on the directory%n", closeHandlesInfo.getFailedHandles());
For more information, see the Azure Docs.
recursive
- Flag indicating if the operation should apply to all subdirectories and files contained in the
directory.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.public ShareDirectoryClient createSubdirectory(String subdirectoryName)
Code Samples
Create the sub directory "subdir"
shareDirectoryClient.createSubdirectory("subdir");
System
.out.println("Completed creating the subdirectory.");
For more information, see the Azure Docs.
subdirectoryName
- Name of the subdirectoryShareStorageException
- If the subdirectory has already existed, the parent directory does not exist or
directory is an invalid resource name.public com.azure.core.http.rest.Response<ShareDirectoryClient> createSubdirectoryWithResponse(String subdirectoryName, FileSmbProperties smbProperties, String filePermission, Map<String,String> metadata, Duration timeout, com.azure.core.util.Context context)
Code Samples
Create the subdirectory named "subdir", with metadata
FileSmbProperties
smbProperties = newFileSmbProperties
();String
filePermission = "filePermission";Response
<ShareDirectoryClient
> response = shareDirectoryClient.createSubdirectoryWithResponse("subdir", smbProperties, filePermission,Collections
.singletonMap("directory", "metadata"),Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.printf("Creating the sub directory completed with status code %d", response.getStatusCode());
For more information, see the Azure Docs.
subdirectoryName
- Name of the subdirectorysmbProperties
- The SMB properties of the directory.filePermission
- The file permission of the directory.metadata
- Optional metadata to associate with the subdirectorytimeout
- 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 directory has already existed, the parent directory does not exist or
subdirectory is an invalid resource name.RuntimeException
- if the operation doesn't complete before the timeout concludes.public void deleteSubdirectory(String subdirectoryName)
Code Samples
Delete the subdirectory named "subdir"
shareDirectoryClient.deleteSubdirectory("mysubdirectory");
System
.out.println("Complete deleting the subdirectory.");
For more information, see the Azure Docs.
subdirectoryName
- Name of the subdirectoryShareStorageException
- If the subdirectory doesn't exist, the parent directory does not exist or
subdirectory name is an invalid resource name.public com.azure.core.http.rest.Response<Void> deleteSubdirectoryWithResponse(String subdirectoryName, Duration timeout, com.azure.core.util.Context context)
Code Samples
Delete the subdirectory named "subdir"
Response
<Void
> response = shareDirectoryClient.deleteSubdirectoryWithResponse("mysubdirectory",Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.println("Completed deleting the subdirectory with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
subdirectoryName
- Name of the subdirectorycontext
- Additional context that is passed through the Http pipeline during the service call.timeout
- An optional timeout applied to the operation. If a response is not returned before the timeout
concludes a RuntimeException
will be thrown.ShareStorageException
- If the subdirectory doesn't exist, the parent directory does not exist or
subdirectory name is an invalid resource name.RuntimeException
- if the operation doesn't complete before the timeout concludes.public ShareFileClient createFile(String fileName, long maxSize)
Code Samples
Create 1k file with named "myFile"
ShareFileClient
response = shareDirectoryClient.createFile("myfile", 1024);System
.out.println("Completed creating the file: " + response);
For more information, see the Azure Docs.
fileName
- Name of the filemaxSize
- Size of the fileShareStorageException
- If the file has already existed, the parent directory does not exist or file name
is an invalid resource name.public com.azure.core.http.rest.Response<ShareFileClient> createFileWithResponse(String fileName, long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map<String,String> metadata, Duration timeout, com.azure.core.util.Context context)
Code Samples
Create the file named "myFile"
ShareFileHttpHeaders
httpHeaders = newShareFileHttpHeaders
() .setContentType("text/html") .setContentEncoding("gzip") .setContentLanguage("en") .setCacheControl("no-transform") .setContentDisposition("attachment");FileSmbProperties
smbProperties = newFileSmbProperties
() .setNtfsFileAttributes(EnumSet
.of(NtfsFileAttributes
.READ_ONLY)) .setFileCreationTime(OffsetDateTime
.now()) .setFileLastWriteTime(OffsetDateTime
.now()) .setFilePermissionKey("filePermissionKey");String
filePermission = "filePermission"; // NOTE: filePermission and filePermissionKey should never be both setResponse
<ShareFileClient
> response = shareDirectoryClient.createFileWithResponse("myFile", 1024, httpHeaders, smbProperties, filePermission,Collections
.singletonMap("directory", "metadata"),Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.println("Completed creating the file with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
fileName
- Name of the filemaxSize
- Max size of the filehttpHeaders
- The user settable file http headers.smbProperties
- The user settable file smb properties.filePermission
- THe file permission of the file.metadata
- Optional name-value pairs associated with the file as metadata.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.ShareStorageException
- If the directory has already existed, the parent directory does not exist or file
name is an invalid resource name.RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<ShareFileClient> createFileWithResponse(String fileName, long maxSize, ShareFileHttpHeaders httpHeaders, FileSmbProperties smbProperties, String filePermission, Map<String,String> metadata, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
Code Samples
Create the file named "myFile"
ShareFileHttpHeaders
httpHeaders = newShareFileHttpHeaders
() .setContentType("text/html") .setContentEncoding("gzip") .setContentLanguage("en") .setCacheControl("no-transform") .setContentDisposition("attachment");FileSmbProperties
smbProperties = newFileSmbProperties
() .setNtfsFileAttributes(EnumSet
.of(NtfsFileAttributes
.READ_ONLY)) .setFileCreationTime(OffsetDateTime
.now()) .setFileLastWriteTime(OffsetDateTime
.now()) .setFilePermissionKey("filePermissionKey");String
filePermission = "filePermission"; // NOTE: filePermission and filePermissionKey should never be both setShareRequestConditions
requestConditions = newShareRequestConditions
().setLeaseId(leaseId);Response
<ShareFileClient
> response = shareDirectoryClient.createFileWithResponse("myFile", 1024, httpHeaders, smbProperties, filePermission,Collections
.singletonMap("directory", "metadata"), requestConditions,Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.println("Completed creating the file with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
fileName
- Name of the filemaxSize
- Max size of the filehttpHeaders
- The user settable file http headers.smbProperties
- The user settable file smb properties.filePermission
- THe file permission of the file.metadata
- Optional name-value pairs associated with the file as metadata.requestConditions
- ShareRequestConditions
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.ShareStorageException
- If the directory has already existed, the parent directory does not exist or file
name is an invalid resource name.RuntimeException
- if the operation doesn't complete before the timeout concludes.public void deleteFile(String fileName)
Code Samples
Delete the file "filetest"
shareDirectoryClient.deleteFile("myfile");
System
.out.println("Completed deleting the file.");
For more information, see the Azure Docs.
fileName
- Name of the fileShareStorageException
- If the directory doesn't exist or the file doesn't exist or file name is an invalid
resource name.public com.azure.core.http.rest.Response<Void> deleteFileWithResponse(String fileName, Duration timeout, com.azure.core.util.Context context)
Code Samples
Delete the file "filetest"
Response
<Void
> response = shareDirectoryClient.deleteFileWithResponse("myfile",Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.println("Completed deleting the file with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
fileName
- Name of the filetimeout
- 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 directory doesn't exist or the file doesn't exist or file name is an invalid
resource name.RuntimeException
- if the operation doesn't complete before the timeout concludes.public com.azure.core.http.rest.Response<Void> deleteFileWithResponse(String fileName, ShareRequestConditions requestConditions, Duration timeout, com.azure.core.util.Context context)
Code Samples
Delete the file "filetest"
ShareRequestConditions
requestConditions = newShareRequestConditions
().setLeaseId(leaseId);Response
<Void
> response = shareDirectoryClient.deleteFileWithResponse("myfile", requestConditions,Duration
.ofSeconds(1), newContext
(key1, value1));System
.out.println("Completed deleting the file with status code: " + response.getStatusCode());
For more information, see the Azure Docs.
fileName
- Name of the filerequestConditions
- ShareRequestConditions
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.ShareStorageException
- If the directory doesn't exist or the file doesn't exist or file name is an invalid
resource name.RuntimeException
- if the operation doesn't complete before the timeout concludes.public String getShareSnapshotId()
ShareDirectoryClient
. Return null
if no snapshot id attached.
Code Samples
Get the share snapshot id.
OffsetDateTime
currentTime =OffsetDateTime
.of(LocalDateTime
.now(),ZoneOffset
.UTC);ShareDirectoryClient
shareDirectoryClient = newShareFileClientBuilder
() .endpoint("https://${accountName}.file.core.windows.net") .sasToken("${SASToken}") .shareName("myshare") .resourcePath("mydirectory") .snapshot(currentTime.toString()) .buildDirectoryClient();System
.out.printf("Snapshot ID: %s%n", shareDirectoryClient.getShareSnapshotId());
DateTime
value that identifies the share snapshot to its base
share.public String getShareName()
Get the share name.
String
shareName = directoryAsyncClient.getShareName();System
.out.println("The share name of the directory is " + shareName);
public String getDirectoryPath()
Get directory path.
String
directoryPath = shareDirectoryClient.getDirectoryPath();System
.out.println("The name of the directory is " + directoryPath);
public String getAccountName()
public com.azure.core.http.HttpPipeline getHttpPipeline()
HttpPipeline
powering this client.public String generateSas(ShareServiceSasSignatureValues shareServiceSasSignatureValues)
ShareServiceSasSignatureValues
Note : The client must be authenticated via StorageSharedKeyCredential
See ShareServiceSasSignatureValues
for more information on how to construct a service SAS.
Code Samples
OffsetDateTime
expiryTime =OffsetDateTime
.now().plusDays(1);ShareFileSasPermission
permission = newShareFileSasPermission
().setReadPermission(true);ShareServiceSasSignatureValues
values = newShareServiceSasSignatureValues
(expiryTime, permission) .setStartTime(OffsetDateTime
.now()); shareDirectoryClient.generateSas(values); // Client must be authenticated via StorageSharedKeyCredential
shareServiceSasSignatureValues
- ShareServiceSasSignatureValues
String
representing all SAS query parameters.Copyright © 2020 Microsoft Corporation. All rights reserved.