Class ShareFileClient


  • public class ShareFileClient
    extends Object
    This class provides a client that contains all the operations for interacting files under Azure Storage File Service. Operations allowed by the client are creating, uploading, copying, listing, downloading, and deleting files.

    Instantiating a synchronous File Client

     ShareFileClient client = new ShareFileClientBuilder()
         .connectionString("${connectionString}")
         .endpoint("${endpoint}")
         .buildFileClient();
     

    View this for additional ways to construct the client.

    See Also:
    ShareFileClientBuilder, ShareFileAsyncClient, StorageSharedKeyCredential
    • Method Detail

      • getAccountUrl

        public String getAccountUrl()
        Get the url of the storage account.
        Returns:
        the URL of the storage account
      • getFileUrl

        public String getFileUrl()
        Get the url of the storage file client.
        Returns:
        the URL of the storage file client.
      • getServiceVersion

        public ShareServiceVersion getServiceVersion()
        Gets the service version the client is using.
        Returns:
        the service version the client is using.
      • openInputStream

        public final StorageFileInputStream openInputStream()
        Opens a file input stream to download the file.
        Returns:
        An InputStream object that represents the stream to use for reading from the file.
        Throws:
        ShareStorageException - If a storage service error occurred.
      • openInputStream

        public final StorageFileInputStream openInputStream​(ShareFileRange range)
        Opens a file input stream to download the specified range of the file.
        Parameters:
        range - ShareFileRange
        Returns:
        An InputStream object that represents the stream to use for reading from the file.
        Throws:
        ShareStorageException - If a storage service error occurred.
      • getFileOutputStream

        public final StorageFileOutputStream getFileOutputStream()
        Creates and opens an output stream to write data to the file. If the file already exists on the service, it will be overwritten.
        Returns:
        A StorageFileOutputStream object used to write data to the file.
        Throws:
        ShareStorageException - If a storage service error occurred.
      • getFileOutputStream

        public final StorageFileOutputStream getFileOutputStream​(long offset)
        Creates and opens an output stream to write data to the file. If the file already exists on the service, it will be overwritten.
        Parameters:
        offset - Starting point of the upload range, if null it will start from the beginning.
        Returns:
        A StorageFileOutputStream object used to write data to the file.
        Throws:
        ShareStorageException - If a storage service error occurred.
      • exists

        public Boolean exists()
        Determines if the file this client represents exists in the cloud.

        Code Samples

         System.out.printf("Exists? %b%n", client.exists());
         
        Returns:
        Flag indicating existence of the file.
      • existsWithResponse

        public com.azure.core.http.rest.Response<Boolean> existsWithResponse​(Duration timeout,
                                                                             com.azure.core.util.Context context)
        Determines if the file this client represents exists in the cloud.

        Code Samples

         Context context = new Context("Key", "Value");
         System.out.printf("Exists? %b%n", client.existsWithResponse(timeout, context).getValue());
         
        Parameters:
        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.
        Returns:
        Flag indicating existence of the file.
      • create

        public ShareFileInfo create​(long maxSize)
        Creates a file in the storage account and returns a response of ShareFileInfo to interact with it.

        Code Samples

        Create the file with length of 1024 bytes, some headers and metadata.

         ShareFileInfo response = fileClient.create(1024);
         System.out.println("Complete creating the file.");
         

        For more information, see the Azure Docs.

        Parameters:
        maxSize - The maximum size in bytes for the file.
        Returns:
        The file info
        Throws:
        ShareStorageException - If the file has already existed, the parent directory does not exist or fileName is an invalid resource name.
      • createWithResponse

        public com.azure.core.http.rest.Response<ShareFileInfo> createWithResponse​(long maxSize,
                                                                                   ShareFileHttpHeaders httpHeaders,
                                                                                   FileSmbProperties smbProperties,
                                                                                   String filePermission,
                                                                                   Map<String,​String> metadata,
                                                                                   Duration timeout,
                                                                                   com.azure.core.util.Context context)
        Creates a file in the storage account and returns a response of ShareFileInfo to interact with it.

        Code Samples

        Create the file with length of 1024 bytes, some headers, file smb properties and metadata.

         ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
             .setContentType("text/html")
             .setContentEncoding("gzip")
             .setContentLanguage("en")
             .setCacheControl("no-transform")
             .setContentDisposition("attachment");
         FileSmbProperties smbProperties = new FileSmbProperties()
             .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 set
         Response<ShareFileInfo> response = fileClient.createWithResponse(1024, httpHeaders, smbProperties,
             filePermission, Collections.singletonMap("directory", "metadata"), Duration.ofSeconds(1),
             new Context(key1, value1));
         System.out.printf("Creating the file completed with status code %d", response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        maxSize - The maximum size in bytes for the file.
        httpHeaders - 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.
        Returns:
        A response containing the file info and the status of creating the file.
        Throws:
        ShareStorageException - If the directory has already existed, the parent directory does not exist or directory is an invalid resource name.
        RuntimeException - if the operation doesn't complete before the timeout concludes.
        See Also:
        C# identifiers
      • createWithResponse

        public com.azure.core.http.rest.Response<ShareFileInfo> createWithResponse​(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 the storage account and returns a response of ShareFileInfo to interact with it.

        Code Samples

        Create the file with length of 1024 bytes, some headers, file smb properties and metadata.

         ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
             .setContentType("text/html")
             .setContentEncoding("gzip")
             .setContentLanguage("en")
             .setCacheControl("no-transform")
             .setContentDisposition("attachment");
         FileSmbProperties smbProperties = new FileSmbProperties()
             .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 set
        
         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
        
         Response<ShareFileInfo> response = fileClient.createWithResponse(1024, httpHeaders, smbProperties,
             filePermission, Collections.singletonMap("directory", "metadata"), requestConditions, Duration.ofSeconds(1),
             new Context(key1, value1));
         System.out.printf("Creating the file completed with status code %d", response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        maxSize - The maximum size in bytes for the file.
        httpHeaders - 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.
        Returns:
        A response containing the file info and the status of creating the file.
        Throws:
        ShareStorageException - If the directory has already existed, the parent directory does not exist or directory is an invalid resource name.
        RuntimeException - if the operation doesn't complete before the timeout concludes.
        See Also:
        C# identifiers
      • beginCopy

        public com.azure.core.util.polling.SyncPoller<ShareFileCopyInfo,​Void> beginCopy​(String sourceUrl,
                                                                                              Map<String,​String> metadata,
                                                                                              Duration pollInterval)
        Copies a blob or file to a destination file within the storage account.

        Code Samples

        Copy file from source getDirectoryUrl to the resourcePath

         SyncPoller<ShareFileCopyInfo, Void> poller = fileClient.beginCopy(
             "https://{accountName}.file.core.windows.net?{SASToken}",
             Collections.singletonMap("file", "metadata"), Duration.ofSeconds(2));
        
         final PollResponse<ShareFileCopyInfo> pollResponse = poller.poll();
         final ShareFileCopyInfo value = pollResponse.getValue();
         System.out.printf("Copy source: %s. Status: %s.%n", value.getCopySourceUrl(), value.getCopyStatus());
        
         

        For more information, see the Azure Docs.

        Parameters:
        sourceUrl - Specifies the URL of the source file or blob, up to 2 KB in length.
        metadata - Optional name-value pairs associated with the file as metadata. Metadata names must adhere to the naming rules.
        pollInterval - Duration between each poll for the copy status. If none is specified, a default of one second is used.
        Returns:
        A SyncPoller to poll the progress of copy operation.
        See Also:
        C# identifiers
      • beginCopy

        public com.azure.core.util.polling.SyncPoller<ShareFileCopyInfo,​Void> beginCopy​(String sourceUrl,
                                                                                              FileSmbProperties smbProperties,
                                                                                              String filePermission,
                                                                                              PermissionCopyModeType filePermissionCopyMode,
                                                                                              Boolean ignoreReadOnly,
                                                                                              Boolean setArchiveAttribute,
                                                                                              Map<String,​String> metadata,
                                                                                              Duration pollInterval,
                                                                                              ShareRequestConditions destinationRequestConditions)
        Copies a blob or file to a destination file within the storage account.

        Code Samples

        Copy file from source getDirectoryUrl to the resourcePath

         FileSmbProperties smbProperties = new FileSmbProperties()
             .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 set
         boolean ignoreReadOnly = false; // Default value
         boolean setArchiveAttribute = true; // Default value
         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
        
         SyncPoller<ShareFileCopyInfo, Void> poller = fileClient.beginCopy(
             "https://{accountName}.file.core.windows.net?{SASToken}", smbProperties, filePermission,
             PermissionCopyModeType.SOURCE, ignoreReadOnly, setArchiveAttribute,
             Collections.singletonMap("file", "metadata"), Duration.ofSeconds(2), requestConditions);
        
         final PollResponse<ShareFileCopyInfo> pollResponse = poller.poll();
         final ShareFileCopyInfo value = pollResponse.getValue();
         System.out.printf("Copy source: %s. Status: %s.%n", value.getCopySourceUrl(), value.getCopyStatus());
         

        For more information, see the Azure Docs.

        Parameters:
        sourceUrl - Specifies the URL of the source file or blob, up to 2 KB in length.
        smbProperties - The user settable file smb properties.
        filePermission - The file permission of the file.
        filePermissionCopyMode - Mode of file permission acquisition.
        ignoreReadOnly - Whether or not to copy despite target being read only. (default is false)
        setArchiveAttribute - Whether or not the archive attribute is to be set on the target. (default is true)
        metadata - Optional name-value pairs associated with the file as metadata. Metadata names must adhere to the naming rules.
        pollInterval - Duration between each poll for the copy status. If none is specified, a default of one second is used.
        destinationRequestConditions - ShareRequestConditions
        Returns:
        A SyncPoller to poll the progress of copy operation.
        See Also:
        C# identifiers
      • abortCopy

        public void abortCopy​(String copyId)
        Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.

        Code Samples

        Abort copy file from copy id("someCopyId")

         fileClient.abortCopy("someCopyId");
         System.out.println("Abort copying the file completed.");
         

        For more information, see the Azure Docs.

        Parameters:
        copyId - Specifies the copy id which has copying pending status associate with it.
      • abortCopyWithResponse

        public com.azure.core.http.rest.Response<Void> abortCopyWithResponse​(String copyId,
                                                                             Duration timeout,
                                                                             com.azure.core.util.Context context)
        Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.

        Code Samples

        Abort copy file from copy id("someCopyId")

         Response<Void> response = fileClient.abortCopyWithResponse("someCopyId", Duration.ofSeconds(1),
             new Context(key1, value1));
         System.out.printf("Abort copying the file completed with status code %d", response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        copyId - Specifies the copy id which has copying pending status associate with it.
        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.
        Returns:
        A response containing the status of aborting copy the file.
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • abortCopyWithResponse

        public com.azure.core.http.rest.Response<Void> abortCopyWithResponse​(String copyId,
                                                                             ShareRequestConditions requestConditions,
                                                                             Duration timeout,
                                                                             com.azure.core.util.Context context)
        Aborts a pending Copy File operation, and leaves a destination file with zero length and full metadata.

        Code Samples

        Abort copy file from copy id("someCopyId")

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         Response<Void> response = fileClient.abortCopyWithResponse("someCopyId", requestConditions,
             Duration.ofSeconds(1), new Context(key1, value1));
         System.out.printf("Abort copying the file completed with status code %d", response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        copyId - Specifies the copy id which has copying pending status associate with it.
        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.
        Returns:
        A response containing the status of aborting copy the file.
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • downloadToFile

        public ShareFileProperties downloadToFile​(String downloadFilePath)
        Downloads a file from the system, including its metadata and properties into a file specified by the path.

        The file will be created and must not exist, if the file already exists a FileAlreadyExistsException will be thrown.

        Code Samples

        Download the file to current folder.

         fileClient.downloadToFile("somelocalfilepath");
         if (Files.exists(Paths.get("somelocalfilepath"))) {
             System.out.println("Complete downloading the file.");
         }
         

        For more information, see the Azure Docs.

        Parameters:
        downloadFilePath - The path where store the downloaded file
        Returns:
        The properties of the file.
      • downloadToFileWithResponse

        public com.azure.core.http.rest.Response<ShareFileProperties> downloadToFileWithResponse​(String downloadFilePath,
                                                                                                 ShareFileRange range,
                                                                                                 Duration timeout,
                                                                                                 com.azure.core.util.Context context)
        Downloads a file from the system, including its metadata and properties into a file specified by the path.

        The file will be created and must not exist, if the file already exists a FileAlreadyExistsException will be thrown.

        Code Samples

        Download the file from 1024 to 2048 bytes to current folder.

         Response<ShareFileProperties> response =
             fileClient.downloadToFileWithResponse("somelocalfilepath", new ShareFileRange(1024, 2047L),
                 Duration.ofSeconds(1), Context.NONE);
         if (Files.exists(Paths.get("somelocalfilepath"))) {
             System.out.println("Complete downloading the file with status code " + response.getStatusCode());
         }
         

        For more information, see the Azure Docs.

        Parameters:
        downloadFilePath - The path where store the downloaded file
        range - Optional byte range which returns file data only from the specified range.
        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.
        Returns:
        The response of the file properties.
      • downloadToFileWithResponse

        public com.azure.core.http.rest.Response<ShareFileProperties> downloadToFileWithResponse​(String downloadFilePath,
                                                                                                 ShareFileRange range,
                                                                                                 ShareRequestConditions requestConditions,
                                                                                                 Duration timeout,
                                                                                                 com.azure.core.util.Context context)
        Downloads a file from the system, including its metadata and properties into a file specified by the path.

        The file will be created and must not exist, if the file already exists a FileAlreadyExistsException will be thrown.

        Code Samples

        Download the file from 1024 to 2048 bytes to current folder.

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         Response<ShareFileProperties> response =
             fileClient.downloadToFileWithResponse("somelocalfilepath", new ShareFileRange(1024, 2047L),
                 requestConditions, Duration.ofSeconds(1), Context.NONE);
         if (Files.exists(Paths.get("somelocalfilepath"))) {
             System.out.println("Complete downloading the file with status code " + response.getStatusCode());
         }
         

        For more information, see the Azure Docs.

        Parameters:
        downloadFilePath - The path where store the downloaded file
        range - Optional byte range which returns file data only from the specified range.
        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.
        Returns:
        The response of the file properties.
      • download

        public void download​(OutputStream stream)
        Downloads a file from the system, including its metadata and properties

        Code Samples

        Download the file with its metadata and properties.

         try {
             ByteArrayOutputStream stream = new ByteArrayOutputStream();
             fileClient.download(stream);
             System.out.printf("Completed downloading the file with content: %n%s%n",
                 new String(stream.toByteArray(), StandardCharsets.UTF_8));
         } catch (Throwable throwable) {
             System.err.printf("Downloading failed with exception. Message: %s%n", throwable.getMessage());
         }
         

        For more information, see the Azure Docs.

        Parameters:
        stream - A non-null OutputStream where the downloaded data will be written.
        Throws:
        NullPointerException - If stream is null.
      • downloadWithResponse

        public ShareFileDownloadResponse downloadWithResponse​(OutputStream stream,
                                                              ShareFileRange range,
                                                              Boolean rangeGetContentMD5,
                                                              Duration timeout,
                                                              com.azure.core.util.Context context)
        Downloads a file from the system, including its metadata and properties

        Code Samples

        Download the file from 1024 to 2048 bytes with its metadata and properties and without the contentMD5.

         try {
             ByteArrayOutputStream stream = new ByteArrayOutputStream();
             Response<Void> response = fileClient.downloadWithResponse(stream, new ShareFileRange(1024, 2047L), false,
                 Duration.ofSeconds(30), new Context(key1, value1));
        
             System.out.printf("Completed downloading file with status code %d%n", response.getStatusCode());
             System.out.printf("Content of the file is: %n%s%n",
                 new String(stream.toByteArray(), StandardCharsets.UTF_8));
         } catch (Throwable throwable) {
             System.err.printf("Downloading failed with exception. Message: %s%n", throwable.getMessage());
         }
         

        For more information, see the Azure Docs.

        Parameters:
        stream - A non-null OutputStream where the downloaded data will be written.
        range - Optional byte range which returns file data only from the specified range.
        rangeGetContentMD5 - Optional boolean which the service returns the MD5 hash for the range when it sets to true, as long as the range is less than or equal to 4 MB in size.
        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.
        Returns:
        A response containing the headers and response status code
        Throws:
        NullPointerException - If stream is null.
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • downloadWithResponse

        public ShareFileDownloadResponse downloadWithResponse​(OutputStream stream,
                                                              ShareFileRange range,
                                                              Boolean rangeGetContentMD5,
                                                              ShareRequestConditions requestConditions,
                                                              Duration timeout,
                                                              com.azure.core.util.Context context)
        Downloads a file from the system, including its metadata and properties

        Code Samples

        Download the file from 1024 to 2048 bytes with its metadata and properties and without the contentMD5.

         try {
             ByteArrayOutputStream stream = new ByteArrayOutputStream();
             ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
             Response<Void> response = fileClient.downloadWithResponse(stream, new ShareFileRange(1024, 2047L), false,
                 requestConditions, Duration.ofSeconds(30), new Context(key1, value1));
        
             System.out.printf("Completed downloading file with status code %d%n", response.getStatusCode());
             System.out.printf("Content of the file is: %n%s%n",
                 new String(stream.toByteArray(), StandardCharsets.UTF_8));
         } catch (Throwable throwable) {
             System.err.printf("Downloading failed with exception. Message: %s%n", throwable.getMessage());
         }
         

        For more information, see the Azure Docs.

        Parameters:
        stream - A non-null OutputStream where the downloaded data will be written.
        range - Optional byte range which returns file data only from the specified range.
        rangeGetContentMD5 - Optional boolean which the service returns the MD5 hash for the range when it sets to true, as long as the range is less than or equal to 4 MB in size.
        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.
        Returns:
        A response containing the headers and response status code
        Throws:
        NullPointerException - If stream is null.
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • downloadWithResponse

        public ShareFileDownloadResponse downloadWithResponse​(OutputStream stream,
                                                              ShareFileDownloadOptions options,
                                                              Duration timeout,
                                                              com.azure.core.util.Context context)
        Downloads a file from the system, including its metadata and properties

        Code Samples

        Download the file from 1024 to 2048 bytes with its metadata and properties and without the contentMD5.

         try {
             ByteArrayOutputStream stream = new ByteArrayOutputStream();
             ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
             ShareFileRange range = new ShareFileRange(1024, 2047L);
             DownloadRetryOptions retryOptions = new DownloadRetryOptions().setMaxRetryRequests(3);
             ShareFileDownloadOptions options = new ShareFileDownloadOptions().setRange(range)
                 .setRequestConditions(requestConditions)
                 .setRangeContentMd5Requested(false)
                 .setRetryOptions(retryOptions);
             Response<Void> response = fileClient.downloadWithResponse(stream, options, Duration.ofSeconds(30),
                 new Context(key1, value1));
        
             System.out.printf("Completed downloading file with status code %d%n", response.getStatusCode());
             System.out.printf("Content of the file is: %n%s%n",
                 new String(stream.toByteArray(), StandardCharsets.UTF_8));
         } catch (Throwable throwable) {
             System.err.printf("Downloading failed with exception. Message: %s%n", throwable.getMessage());
         }
         

        For more information, see the Azure Docs.

        Parameters:
        stream - A non-null OutputStream where the downloaded data will be written.
        options - ShareFileDownloadOptions
        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.
        Returns:
        A response containing the headers and response status code
        Throws:
        NullPointerException - If stream is null.
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • delete

        public void delete()
        Deletes the file associate with the client.

        Code Samples

        Delete the file

         fileClient.delete();
         System.out.println("Complete deleting the file.");
         

        For more information, see the Azure Docs.

        Throws:
        ShareStorageException - If the directory doesn't exist or the file doesn't exist.
      • deleteWithResponse

        public com.azure.core.http.rest.Response<Void> deleteWithResponse​(Duration timeout,
                                                                          com.azure.core.util.Context context)
        Deletes the file associate with the client.

        Code Samples

        Delete the file

         Response<Void> response = fileClient.deleteWithResponse(Duration.ofSeconds(1), new Context(key1, value1));
         System.out.println("Complete deleting the file with status code: " + response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        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.
        Returns:
        A response that only contains headers and response status code
        Throws:
        ShareStorageException - If the directory doesn't exist or the file doesn't exist.
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • deleteWithResponse

        public com.azure.core.http.rest.Response<Void> deleteWithResponse​(ShareRequestConditions requestConditions,
                                                                          Duration timeout,
                                                                          com.azure.core.util.Context context)
        Deletes the file associate with the client.

        Code Samples

        Delete the file

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         Response<Void> response = fileClient.deleteWithResponse(requestConditions, Duration.ofSeconds(1),
             new Context(key1, value1));
         System.out.println("Complete deleting the file with status code: " + response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        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.
        Returns:
        A response that only contains headers and response status code
        Throws:
        ShareStorageException - If the directory doesn't exist or the file doesn't exist.
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • getProperties

        public ShareFileProperties getProperties()
        Retrieves the properties of the storage account's file. The properties includes file metadata, last modified date, is server encrypted, and eTag.

        Code Samples

        Retrieve file properties

         ShareFileProperties properties = fileClient.getProperties();
         System.out.printf("File latest modified date is %s.", properties.getLastModified());
         

        For more information, see the Azure Docs.

        Returns:
        Storage file properties
      • getPropertiesWithResponse

        public com.azure.core.http.rest.Response<ShareFileProperties> getPropertiesWithResponse​(Duration timeout,
                                                                                                com.azure.core.util.Context context)
        Retrieves the properties of the storage account's file. The properties includes file metadata, last modified date, is server encrypted, and eTag.

        Code Samples

        Retrieve file properties

         Response<ShareFileProperties> response = fileClient.getPropertiesWithResponse(
             Duration.ofSeconds(1), new Context(key1, value1));
         System.out.printf("File latest modified date is %s.", response.getValue().getLastModified());
         

        For more information, see the Azure Docs.

        Parameters:
        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.
        Returns:
        A response containing the Storage file properties with headers and status code.
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • getPropertiesWithResponse

        public com.azure.core.http.rest.Response<ShareFileProperties> getPropertiesWithResponse​(ShareRequestConditions requestConditions,
                                                                                                Duration timeout,
                                                                                                com.azure.core.util.Context context)
        Retrieves the properties of the storage account's file. The properties includes file metadata, last modified date, is server encrypted, and eTag.

        Code Samples

        Retrieve file properties

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         Response<ShareFileProperties> response = fileClient.getPropertiesWithResponse(requestConditions,
             Duration.ofSeconds(1), new Context(key1, value1));
         System.out.printf("File latest modified date is %s.", response.getValue().getLastModified());
         

        For more information, see the Azure Docs.

        Parameters:
        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.
        Returns:
        A response containing the Storage file properties with headers and status code.
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • setProperties

        public ShareFileInfo setProperties​(long newFileSize,
                                           ShareFileHttpHeaders httpHeaders,
                                           FileSmbProperties smbProperties,
                                           String filePermission)
        Sets the user-defined httpHeaders to associate to the file.

        If null is passed for the httpHeaders it will clear the httpHeaders associated to the file.

        Code Samples

        Set the httpHeaders of contentType of "text/plain"

         ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
             .setContentType("text/html")
             .setContentEncoding("gzip")
             .setContentLanguage("en")
             .setCacheControl("no-transform")
             .setContentDisposition("attachment");
         FileSmbProperties smbProperties = new FileSmbProperties()
             .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 set
         fileClient.setProperties(1024, httpHeaders, smbProperties, filePermission);
         System.out.println("Setting the file httpHeaders completed.");
         

        Clear the httpHeaders of the file and preserve the SMB properties

         ShareFileInfo response = fileClient.setProperties(1024, null, null, null);
         System.out.println("Setting the file httpHeaders completed.");
         

        For more information, see the Azure Docs.

        Parameters:
        newFileSize - New file size of the file
        httpHeaders - The user settable file http headers.
        smbProperties - The user settable file smb properties.
        filePermission - The file permission of the file
        Returns:
        The file info
        Throws:
        IllegalArgumentException - thrown if parameters fail the validation.
      • setPropertiesWithResponse

        public com.azure.core.http.rest.Response<ShareFileInfo> setPropertiesWithResponse​(long newFileSize,
                                                                                          ShareFileHttpHeaders httpHeaders,
                                                                                          FileSmbProperties smbProperties,
                                                                                          String filePermission,
                                                                                          Duration timeout,
                                                                                          com.azure.core.util.Context context)
        Sets the user-defined httpHeaders to associate to the file.

        If null is passed for the httpHeaders it will clear the httpHeaders associated to the file.

        Code Samples

        Set the httpHeaders of contentType of "text/plain"

         ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
             .setContentType("text/html")
             .setContentEncoding("gzip")
             .setContentLanguage("en")
             .setCacheControl("no-transform")
             .setContentDisposition("attachment");
         FileSmbProperties smbProperties = new FileSmbProperties()
             .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 set
         Response<ShareFileInfo> response = fileClient.setPropertiesWithResponse(1024, httpHeaders, smbProperties,
             filePermission, Duration.ofSeconds(1), new Context(key1, value1));
         System.out.printf("Setting the file httpHeaders completed with status code %d", response.getStatusCode());
         

        Clear the httpHeaders of the file and preserve the SMB properties

         Response<ShareFileInfo> response = fileClient.setPropertiesWithResponse(1024, null, null, null,
             Duration.ofSeconds(1), new Context(key1, value1));
         System.out.printf("Setting the file httpHeaders completed with status code %d", response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        newFileSize - New file size of the file
        httpHeaders - The user settable file http headers.
        smbProperties - The user settable file smb properties.
        filePermission - The file permission of the file
        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.
        Returns:
        Response containing the file info with headers and status code
        Throws:
        IllegalArgumentException - thrown if parameters fail the validation.
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • setPropertiesWithResponse

        public com.azure.core.http.rest.Response<ShareFileInfo> setPropertiesWithResponse​(long newFileSize,
                                                                                          ShareFileHttpHeaders httpHeaders,
                                                                                          FileSmbProperties smbProperties,
                                                                                          String filePermission,
                                                                                          ShareRequestConditions requestConditions,
                                                                                          Duration timeout,
                                                                                          com.azure.core.util.Context context)
        Sets the user-defined httpHeaders to associate to the file.

        If null is passed for the httpHeaders it will clear the httpHeaders associated to the file.

        Code Samples

        Set the httpHeaders of contentType of "text/plain"

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         ShareFileHttpHeaders httpHeaders = new ShareFileHttpHeaders()
             .setContentType("text/html")
             .setContentEncoding("gzip")
             .setContentLanguage("en")
             .setCacheControl("no-transform")
             .setContentDisposition("attachment");
         FileSmbProperties smbProperties = new FileSmbProperties()
             .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 set
         fileClient.setPropertiesWithResponse(1024, httpHeaders, smbProperties, filePermission, requestConditions, null,
             null);
         System.out.println("Setting the file httpHeaders completed.");
         

        Clear the httpHeaders of the file and preserve the SMB properties

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         Response<ShareFileInfo> response = fileClient.setPropertiesWithResponse(1024, null, null, null, requestConditions,
             Duration.ofSeconds(1), new Context(key1, value1));
         System.out.printf("Setting the file httpHeaders completed with status code %d", response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        newFileSize - New file size of the file
        httpHeaders - The user settable file http headers.
        smbProperties - The user settable file smb properties.
        filePermission - The file permission of the file
        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.
        Returns:
        Response containing the file info with headers and status code
        Throws:
        IllegalArgumentException - thrown if parameters fail the validation.
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • setMetadata

        public ShareFileMetadataInfo setMetadata​(Map<String,​String> metadata)
        Sets the user-defined metadata to associate to the file.

        If null is passed for the metadata it will clear the metadata associated to the file.

        Code Samples

        Set the metadata to "file:updatedMetadata"

         fileClient.setMetadata(Collections.singletonMap("file", "updatedMetadata"));
         System.out.println("Setting the file metadata completed.");
         

        Clear the metadata of the file

         fileClient.setMetadata(null);
         System.out.println("Setting the file metadata completed.");
         

        For more information, see the Azure Docs.

        Parameters:
        metadata - Options.Metadata to set on the file, if null is passed the metadata for the file is cleared
        Returns:
        The file meta info
        Throws:
        ShareStorageException - If the file doesn't exist or the metadata contains invalid keys
      • setMetadataWithResponse

        public com.azure.core.http.rest.Response<ShareFileMetadataInfo> setMetadataWithResponse​(Map<String,​String> metadata,
                                                                                                Duration timeout,
                                                                                                com.azure.core.util.Context context)
        Sets the user-defined metadata to associate to the file.

        If null is passed for the metadata it will clear the metadata associated to the file.

        Code Samples

        Set the metadata to "file:updatedMetadata"

         Response<ShareFileMetadataInfo> response = fileClient.setMetadataWithResponse(
             Collections.singletonMap("file", "updatedMetadata"), Duration.ofSeconds(1), new Context(key1, value1));
         System.out.printf("Setting the file metadata completed with status code %d", response.getStatusCode());
         

        Clear the metadata of the file

         Response<ShareFileMetadataInfo> response = fileClient.setMetadataWithResponse(null,
             Duration.ofSeconds(1), new Context(key1, value1));
         System.out.printf("Setting the file metadata completed with status code %d", response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        metadata - Options.Metadata to set on the file, if null is passed the metadata for the file is cleared
        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.
        Returns:
        Response containing the file meta info with headers and status code
        Throws:
        ShareStorageException - If the file doesn't exist or the metadata contains invalid keys
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • setMetadataWithResponse

        public com.azure.core.http.rest.Response<ShareFileMetadataInfo> setMetadataWithResponse​(Map<String,​String> metadata,
                                                                                                ShareRequestConditions requestConditions,
                                                                                                Duration timeout,
                                                                                                com.azure.core.util.Context context)
        Sets the user-defined metadata to associate to the file.

        If null is passed for the metadata it will clear the metadata associated to the file.

        Code Samples

        Set the metadata to "file:updatedMetadata"

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         Response<ShareFileMetadataInfo> response = fileClient.setMetadataWithResponse(
             Collections.singletonMap("file", "updatedMetadata"), requestConditions, Duration.ofSeconds(1),
             new Context(key1, value1));
         System.out.printf("Setting the file metadata completed with status code %d", response.getStatusCode());
         

        Clear the metadata of the file

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         Response<ShareFileMetadataInfo> response = fileClient.setMetadataWithResponse(null, requestConditions,
             Duration.ofSeconds(1), new Context(key1, value1));
         System.out.printf("Setting the file metadata completed with status code %d", response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        metadata - Options.Metadata to set on the file, if null is passed the metadata for the file is cleared
        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.
        Returns:
        Response containing the file meta info with headers and status code
        Throws:
        ShareStorageException - If the file doesn't exist or the metadata contains invalid keys
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • upload

        @Deprecated
        public ShareFileUploadInfo upload​(InputStream data,
                                          long length)
        Deprecated.
        Use uploadRange(InputStream, long) instead. Or consider upload(InputStream, long, ParallelTransferOptions) for an upload that can handle large amounts of data.
        Uploads a range of bytes to the beginning of a file in storage file service. Upload operations performs an in-place write on the specified file.

        Code Samples

        Upload data "default" to the file in Storage File Service.

         InputStream uploadData = new ByteArrayInputStream(data);
         ShareFileUploadInfo response = fileClient.upload(uploadData, data.length);
         System.out.println("Complete uploading the data with eTag: " + response.getETag());
         

        For more information, see the Azure Docs.

        Parameters:
        data - The data which will upload to the storage file.
        length - Specifies the number of bytes being transmitted in the request body. When the ShareFileRangeWriteType is set to clear, the value of this header must be set to zero.
        Returns:
        The file upload info
        Throws:
        ShareStorageException - If you attempt to upload a range that is larger than 4 MB, the service returns status code 413 (Request Entity Too Large)
      • uploadWithResponse

        @Deprecated
        public com.azure.core.http.rest.Response<ShareFileUploadInfo> uploadWithResponse​(InputStream data,
                                                                                         long length,
                                                                                         Long offset,
                                                                                         Duration timeout,
                                                                                         com.azure.core.util.Context context)
        Deprecated.
        Uploads a range of bytes to specific of a file in storage file service. Upload operations performs an in-place write on the specified file.

        Code Samples

        Upload data "default" starting from 1024.

         InputStream uploadData = new ByteArrayInputStream(data);
         Response<ShareFileUploadInfo> response = fileClient.uploadWithResponse(uploadData, data.length, 0L,
             Duration.ofSeconds(30), null);
         System.out.printf("Completed uploading the data with response %d%n.", response.getStatusCode());
         System.out.printf("ETag of the file is %s%n", response.getValue().getETag());
         

        For more information, see the Azure Docs.

        Parameters:
        data - The data which will upload to the storage file.
        length - Specifies the number of bytes being transmitted in the request body.
        offset - Starting point of the upload range, if null it will start from the beginning.
        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.
        Returns:
        A response containing the file upload info with headers and response status code.
        Throws:
        ShareStorageException - If you attempt to upload a range that is larger than 4 MB, the service returns status code 413 (Request Entity Too Large)
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • uploadWithResponse

        @Deprecated
        public com.azure.core.http.rest.Response<ShareFileUploadInfo> uploadWithResponse​(InputStream data,
                                                                                         long length,
                                                                                         Long offset,
                                                                                         ShareRequestConditions requestConditions,
                                                                                         Duration timeout,
                                                                                         com.azure.core.util.Context context)
        Deprecated.
        Uploads a range of bytes to specific of a file in storage file service. Upload operations performs an in-place write on the specified file.

        Code Samples

        Upload data "default" starting from 1024.

         InputStream uploadData = new ByteArrayInputStream(data);
         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         Response<ShareFileUploadInfo> response = fileClient.uploadWithResponse(uploadData, data.length, 0L,
             requestConditions, Duration.ofSeconds(30), null);
         System.out.printf("Completed uploading the data with response %d%n.", response.getStatusCode());
         System.out.printf("ETag of the file is %s%n", response.getValue().getETag());
         

        For more information, see the Azure Docs.

        Parameters:
        data - The data which will upload to the storage file.
        length - Specifies the number of bytes being transmitted in the request body.
        offset - Starting point of the upload range, if null it will start from the beginning.
        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.
        Returns:
        A response containing the file upload info with headers and response status code.
        Throws:
        ShareStorageException - If you attempt to upload a range that is larger than 4 MB, the service returns status code 413 (Request Entity Too Large)
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • upload

        public ShareFileUploadInfo upload​(InputStream data,
                                          long length,
                                          ParallelTransferOptions transferOptions)
        Buffers a range of bytes and uploads sub-ranges in parallel to a file in storage file service. Upload operations perform an in-place write on the specified file.

        Code Samples

        Upload data "default" to the file in Storage File Service.

         InputStream uploadData = new ByteArrayInputStream(data);
         ShareFileUploadInfo response = shareFileClient.upload(uploadData, data.length, null);
         System.out.println("Complete uploading the data with eTag: " + response.getETag());
         

        For more information, see the Azure Docs.

        Parameters:
        data - The data which will upload to the storage file.
        length - Specifies the number of bytes being transmitted in the request body.
        transferOptions - ParallelTransferOptions for file transfer.
        Returns:
        The file upload info
      • uploadWithResponse

        public com.azure.core.http.rest.Response<ShareFileUploadInfo> uploadWithResponse​(ShareFileUploadOptions options,
                                                                                         Duration timeout,
                                                                                         com.azure.core.util.Context context)
        Buffers a range of bytes and uploads sub-ranges in parallel to a file in storage file service. Upload operations perform an in-place write on the specified file.

        Code Samples

        Upload data "default" to the file in Storage File Service.

         InputStream uploadData = new ByteArrayInputStream(data);
         Response<ShareFileUploadInfo> response = shareFileAsyncClient.uploadWithResponse(
             new ShareFileUploadOptions(uploadData, data.length), Duration.ofSeconds(30), null);
         System.out.printf("Completed uploading the data with response %d%n.", response.getStatusCode());
         System.out.printf("ETag of the file is %s%n", response.getValue().getETag());
         

        For more information, see the Azure Docs.

        Parameters:
        options - Argument collection for the upload operation.
        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.
        Returns:
        The file upload info
      • uploadRange

        public ShareFileUploadInfo uploadRange​(InputStream data,
                                               long length)
        Uploads a range of bytes to the specified offset of a file in storage file service. Upload operations perform an in-place write on the specified file.

        Code Samples

        Upload data "default" to the file in Storage File Service.

         InputStream uploadData = new ByteArrayInputStream(data);
         ShareFileUploadInfo response = shareFileClient.uploadRange(uploadData, data.length);
         System.out.println("Complete uploading the data with eTag: " + response.getETag());
         

        This method does a single Put Range operation. For more information, see the Azure Docs.

        Parameters:
        data - The data which will upload to the storage file.
        length - Specifies the number of bytes being transmitted in the request body.
        Returns:
        The file upload info
        Throws:
        ShareStorageException - If you attempt to upload a range that is larger than 4 MB, the service returns status code 413 (Request Entity Too Large)
      • uploadRangeWithResponse

        public com.azure.core.http.rest.Response<ShareFileUploadInfo> uploadRangeWithResponse​(ShareFileUploadRangeOptions options,
                                                                                              Duration timeout,
                                                                                              com.azure.core.util.Context context)
        Uploads a range of bytes to the specified offset of a file in storage file service. Upload operations perform an in-place write on the specified file.

        Code Samples

        Upload data "default" to the file in Storage File Service.

         InputStream uploadData = new ByteArrayInputStream(data);
         Response<ShareFileUploadInfo> response = shareFileClient.uploadRangeWithResponse(
             new ShareFileUploadRangeOptions(uploadData, data.length), Duration.ofSeconds(30), null);
         System.out.printf("Completed uploading the data with response %d%n.", response.getStatusCode());
         System.out.printf("ETag of the file is %s%n", response.getValue().getETag());
         

        This method does a single Put Range operation. For more information, see the Azure Docs.

        Parameters:
        options - Argument collection for the upload operation.
        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.
        Returns:
        The file upload info
        Throws:
        ShareStorageException - If you attempt to upload a range that is larger than 4 MB, the service returns status code 413 (Request Entity Too Large)
      • uploadRangeFromUrl

        public ShareFileUploadRangeFromUrlInfo uploadRangeFromUrl​(long length,
                                                                  long destinationOffset,
                                                                  long sourceOffset,
                                                                  String sourceUrl)
        Uploads a range of bytes from one file to another file.

        Code Samples

        Upload a number of bytes from a file at defined source and destination offsets

         ShareFileUploadRangeFromUrlInfo response = fileClient.uploadRangeFromUrl(6, 8, 0, "sourceUrl");
         System.out.println("Completed upload range from url!");
         

        For more information, see the Azure Docs.

        Parameters:
        length - Specifies the number of bytes being transmitted in the request body.
        destinationOffset - Starting point of the upload range on the destination.
        sourceOffset - Starting point of the upload range on the source.
        sourceUrl - Specifies the URL of the source file.
        Returns:
        The file upload range from url info
      • uploadRangeFromUrlWithResponse

        public com.azure.core.http.rest.Response<ShareFileUploadRangeFromUrlInfo> uploadRangeFromUrlWithResponse​(long length,
                                                                                                                 long destinationOffset,
                                                                                                                 long sourceOffset,
                                                                                                                 String sourceUrl,
                                                                                                                 Duration timeout,
                                                                                                                 com.azure.core.util.Context context)
        Uploads a range of bytes from one file to another file.

        Code Samples

        Upload a number of bytes from a file at defined source and destination offsets

         Response<ShareFileUploadRangeFromUrlInfo> response =
             fileClient.uploadRangeFromUrlWithResponse(6, 8, 0, "sourceUrl", Duration.ofSeconds(1), Context.NONE);
         System.out.println("Completed upload range from url!");
         

        For more information, see the Azure Docs.

        Parameters:
        length - Specifies the number of bytes being transmitted in the request body.
        destinationOffset - Starting point of the upload range on the destination.
        sourceOffset - Starting point of the upload range on the source.
        sourceUrl - Specifies the URL of the source file.
        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.
        Returns:
        A response containing the file upload range from url info with headers and response status code.
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • uploadRangeFromUrlWithResponse

        public com.azure.core.http.rest.Response<ShareFileUploadRangeFromUrlInfo> uploadRangeFromUrlWithResponse​(long length,
                                                                                                                 long destinationOffset,
                                                                                                                 long sourceOffset,
                                                                                                                 String sourceUrl,
                                                                                                                 ShareRequestConditions requestConditions,
                                                                                                                 Duration timeout,
                                                                                                                 com.azure.core.util.Context context)
        Uploads a range of bytes from one file to another file.

        Code Samples

        Upload a number of bytes from a file at defined source and destination offsets

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         Response<ShareFileUploadRangeFromUrlInfo> response = fileClient.uploadRangeFromUrlWithResponse(6, 8, 0,
             "sourceUrl", requestConditions, Duration.ofSeconds(1), Context.NONE);
         System.out.println("Completed upload range from url!");
         

        For more information, see the Azure Docs.

        Parameters:
        length - Specifies the number of bytes being transmitted in the request body.
        destinationOffset - Starting point of the upload range on the destination.
        sourceOffset - Starting point of the upload range on the source.
        sourceUrl - Specifies the URL of the source file.
        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.
        Returns:
        A response containing the file upload range from url info with headers and response status code.
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • uploadRangeFromUrlWithResponse

        public com.azure.core.http.rest.Response<ShareFileUploadRangeFromUrlInfo> uploadRangeFromUrlWithResponse​(ShareFileUploadRangeFromUrlOptions options,
                                                                                                                 Duration timeout,
                                                                                                                 com.azure.core.util.Context context)
        Uploads a range of bytes from one file to another file.

        Code Samples

        Upload a number of bytes from a file at defined source and destination offsets

         Response<ShareFileUploadRangeFromUrlInfo> response =
             fileClient.uploadRangeFromUrlWithResponse(new ShareFileUploadRangeFromUrlOptions(6, "sourceUrl")
                 .setDestinationOffset(8), Duration.ofSeconds(1), Context.NONE);
         System.out.println("Completed upload range from url!");
         

        For more information, see the Azure Docs.

        Parameters:
        options - argument collection
        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.
        Returns:
        A response containing the file upload range from url info with headers and response status code.
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • clearRange

        public ShareFileUploadInfo clearRange​(long length)
        Clears a range of bytes to specific of a file in storage file service. Clear operations performs an in-place write on the specified file.

        Code Samples

        Clears the first 1024 bytes.

         ShareFileUploadInfo response = fileClient.clearRange(1024);
         System.out.println("Complete clearing the range with eTag: " + response.getETag());
         

        For more information, see the Azure Docs.

        Parameters:
        length - Specifies the number of bytes being cleared.
        Returns:
        The file upload info
      • clearRangeWithResponse

        public com.azure.core.http.rest.Response<ShareFileUploadInfo> clearRangeWithResponse​(long length,
                                                                                             long offset,
                                                                                             Duration timeout,
                                                                                             com.azure.core.util.Context context)
        Clears a range of bytes to specific of a file in storage file service. Upload operations performs an in-place write on the specified file.

        Code Samples

        Clear the range starting from 1024 with length of 1024.

         Response<ShareFileUploadInfo> response = fileClient.clearRangeWithResponse(1024, 1024,
             Duration.ofSeconds(1), new Context(key1, value1));
         System.out.println("Complete clearing the range with status code: " + response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        length - Specifies the number of bytes being transmitted in the request body.
        offset - Starting point of the upload range, if null it will start from the beginning.
        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.
        Returns:
        A response containing the file upload info with headers and response status code.
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • clearRangeWithResponse

        public com.azure.core.http.rest.Response<ShareFileUploadInfo> clearRangeWithResponse​(long length,
                                                                                             long offset,
                                                                                             ShareRequestConditions requestConditions,
                                                                                             Duration timeout,
                                                                                             com.azure.core.util.Context context)
        Clears a range of bytes to specific of a file in storage file service. Upload operations performs an in-place write on the specified file.

        Code Samples

        Clear the range starting from 1024 with length of 1024.

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         Response<ShareFileUploadInfo> response = fileClient.clearRangeWithResponse(1024, 1024, requestConditions,
             Duration.ofSeconds(1), new Context(key1, value1));
         System.out.println("Complete clearing the range with status code: " + response.getStatusCode());
         

        For more information, see the Azure Docs.

        Parameters:
        length - Specifies the number of bytes being transmitted in the request body.
        offset - Starting point of the upload range, if null it will start from the beginning.
        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.
        Returns:
        A response containing the file upload info with headers and response status code.
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • uploadFromFile

        public void uploadFromFile​(String uploadFilePath)
        Uploads file to storage file service.

        Code Samples

        Upload the file from the source file path.

         fileClient.uploadFromFile("someFilePath");
         

        For more information, see the Azure Docs Create File and Azure Docs Upload.

        Parameters:
        uploadFilePath - The path where store the source file to upload
      • uploadFromFile

        public void uploadFromFile​(String uploadFilePath,
                                   ShareRequestConditions requestConditions)
        Uploads file to storage file service.

        Code Samples

        Upload the file from the source file path.

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         fileClient.uploadFromFile("someFilePath", requestConditions);
         

        For more information, see the Azure Docs Create File and Azure Docs Upload.

        Parameters:
        uploadFilePath - The path where store the source file to upload
        requestConditions - ShareRequestConditions
      • listRanges

        public com.azure.core.http.rest.PagedIterable<ShareFileRange> listRanges()
        List of valid ranges for a file.

        Code Samples

        List all ranges for the file client.

         Iterable<ShareFileRange> ranges = fileClient.listRanges();
         ranges.forEach(range ->
             System.out.printf("List ranges completed with start: %d, end: %d", range.getStart(), range.getEnd()));
         

        For more information, see the Azure Docs.

        Returns:
        ranges in the files.
      • listRanges

        public com.azure.core.http.rest.PagedIterable<ShareFileRange> listRanges​(ShareFileRange range,
                                                                                 Duration timeout,
                                                                                 com.azure.core.util.Context context)
        List of valid ranges for a file.

        Code Samples

        List all ranges within the file range from 1KB to 2KB.

         Iterable<ShareFileRange> ranges = fileClient.listRanges(new ShareFileRange(1024, 2048L), Duration.ofSeconds(1),
             new Context(key1, value1));
         ranges.forEach(range ->
             System.out.printf("List ranges completed with start: %d, end: %d", range.getStart(), range.getEnd()));
         

        For more information, see the Azure Docs.

        Parameters:
        range - Optional byte range which returns file data only from the specified range.
        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.
        Returns:
        ranges in the files that satisfy the requirements
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • listRanges

        public com.azure.core.http.rest.PagedIterable<ShareFileRange> listRanges​(ShareFileRange range,
                                                                                 ShareRequestConditions requestConditions,
                                                                                 Duration timeout,
                                                                                 com.azure.core.util.Context context)
        List of valid ranges for a file.

        Code Samples

        List all ranges within the file range from 1KB to 2KB.

         ShareRequestConditions requestConditions = new ShareRequestConditions().setLeaseId(leaseId);
         Iterable<ShareFileRange> ranges = fileClient.listRanges(new ShareFileRange(1024, 2048L), requestConditions,
             Duration.ofSeconds(1), new Context(key1, value1));
         ranges.forEach(range ->
             System.out.printf("List ranges completed with start: %d, end: %d", range.getStart(), range.getEnd()));
         

        For more information, see the Azure Docs.

        Parameters:
        range - Optional byte range which returns file data only from the specified range.
        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.
        Returns:
        ranges in the files that satisfy the requirements
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • listRangesDiff

        public ShareFileRangeList listRangesDiff​(String previousSnapshot)
        List of valid ranges for a file.

        Code Samples

        List all ranges within the file range from 1KB to 2KB.

         ShareFileRangeList rangeList = fileClient.listRangesDiff("previoussnapshot");
         System.out.println("Valid Share File Ranges are:");
         for (FileRange range : rangeList.getRanges()) {
             System.out.printf("Start: %s, End: %s%n", range.getStart(), range.getEnd());
         }
         

        For more information, see the Azure Docs.

        Parameters:
        previousSnapshot - Specifies that the response will contain only ranges that were changed between target file and previous snapshot. Changed ranges include both updated and cleared ranges. The target file may be a snapshot, as long as the snapshot specified by previousSnapshot is the older of the two.
        Returns:
        ranges in the files that satisfy the requirements
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • listRangesDiffWithResponse

        public com.azure.core.http.rest.Response<ShareFileRangeList> listRangesDiffWithResponse​(ShareFileListRangesDiffOptions options,
                                                                                                Duration timeout,
                                                                                                com.azure.core.util.Context context)
        List of valid ranges for a file.

        Code Samples

        List all ranges within the file range from 1KB to 2KB.

         ShareFileRangeList rangeList = fileClient.listRangesDiffWithResponse(
             new ShareFileListRangesDiffOptions("previoussnapshot")
             .setRange(new ShareFileRange(1024, 2048L)), Duration.ofSeconds(1), new Context(key1, value1)).getValue();
         System.out.println("Valid Share File Ranges are:");
         for (FileRange range : rangeList.getRanges()) {
             System.out.printf("Start: %s, End: %s%n", range.getStart(), range.getEnd());
         }
         

        For more information, see the Azure Docs.

        Parameters:
        options - ShareFileListRangesDiffOptions
        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.
        Returns:
        ranges in the files that satisfy the requirements
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • listHandles

        public com.azure.core.http.rest.PagedIterable<HandleItem> listHandles()
        List of open handles on a file.

        Code Samples

        List all handles for the file client.

         fileClient.listHandles()
             .forEach(handleItem -> System.out.printf("List handles completed with handleId %s",
                 handleItem.getHandleId()));
         

        For more information, see the Azure Docs.

        Returns:
        handles in the files that satisfy the requirements
      • listHandles

        public com.azure.core.http.rest.PagedIterable<HandleItem> listHandles​(Integer maxResultsPerPage,
                                                                              Duration timeout,
                                                                              com.azure.core.util.Context context)
        List of open handles on a file.

        Code Samples

        List 10 handles for the file client.

         fileClient.listHandles(10, Duration.ofSeconds(1), new Context(key1, value1))
             .forEach(handleItem -> System.out.printf("List handles completed with handleId %s",
                 handleItem.getHandleId()));
         

        For more information, see the Azure Docs.

        Parameters:
        maxResultsPerPage - Optional max number of results returned per page
        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.
        Returns:
        handles in the file that satisfy the requirements
        Throws:
        RuntimeException - if the operation doesn't complete before the timeout concludes.
      • forceCloseHandle

        public CloseHandlesInfo forceCloseHandle​(String handleId)
        Closes a handle on the file at the service. This is intended to be used alongside listHandles().

        Code Samples

        Force close handles returned by list handles.

         fileClient.listHandles().forEach(handleItem -> {
             fileClient.forceCloseHandle(handleItem.getHandleId());
             System.out.printf("Closed handle %s on resource %s%n", handleItem.getHandleId(), handleItem.getPath());
         });
         

        For more information, see the Azure Docs.

        Parameters:
        handleId - Handle ID to be closed.
        Returns:
        Information about the closed handles.
      • forceCloseHandleWithResponse

        public com.azure.core.http.rest.Response<CloseHandlesInfo> forceCloseHandleWithResponse​(String handleId,
                                                                                                Duration timeout,
                                                                                                com.azure.core.util.Context context)
        Closes a handle on the file at the service. This is intended to be used alongside listHandles().

        Code Samples

        Force close handles returned by list handles.

         fileClient.listHandles().forEach(handleItem -> {
             Response<CloseHandlesInfo> closeResponse = fileClient
                 .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.

        Parameters:
        handleId - Handle ID to be closed.
        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.
        Returns:
        A response that contains information about the closed handles, headers and response status code.
      • forceCloseAllHandles

        public CloseHandlesInfo forceCloseAllHandles​(Duration timeout,
                                                     com.azure.core.util.Context context)
        Closes all handles opened on the file at the service.

        Code Samples

        Force close all handles.

         CloseHandlesInfo closeHandlesInfo = fileClient.forceCloseAllHandles(Duration.ofSeconds(30), Context.NONE);
         System.out.printf("Closed %d open handles on the file%n", closeHandlesInfo.getClosedHandles());
         System.out.printf("Failed to close %d open handles on the file%n", closeHandlesInfo.getFailedHandles());
         

        For more information, see the Azure Docs.

        Parameters:
        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.
        Returns:
        Information about the closed handles
      • getShareSnapshotId

        public String getShareSnapshotId()
        Get snapshot id which attached to ShareFileClient. Return null if no snapshot id attached.

        Code Samples

        Get the share snapshot id.

         OffsetDateTime currentTime = OffsetDateTime.of(LocalDateTime.now(), ZoneOffset.UTC);
         ShareFileClient fileClient = new ShareFileClientBuilder()
             .endpoint("https://${accountName}.file.core.windows.net")
             .sasToken("${SASToken}")
             .shareName("myshare")
             .resourcePath("myfile")
             .snapshot(currentTime.toString())
             .buildFileClient();
        
         System.out.printf("Snapshot ID: %s%n", fileClient.getShareSnapshotId());
         
        Returns:
        The snapshot id which is a unique DateTime value that identifies the share snapshot to its base share.
      • getShareName

        public String getShareName()
        Get the share name of file client.

        Get the share name.

         String shareName = fileClient.getShareName();
         System.out.println("The share name of the directory is " + shareName);
         
        Returns:
        The share name of the file.
      • getFilePath

        public String getFilePath()
        Get file path of the client.

        Get the file path.

         String filePath = fileClient.getFilePath();
         System.out.println("The name of the file is " + filePath);
         
        Returns:
        The path of the file.
      • getAccountName

        public String getAccountName()
        Get associated account name.
        Returns:
        account name associated with this storage resource.
      • getHttpPipeline

        public com.azure.core.http.HttpPipeline getHttpPipeline()
        Gets the HttpPipeline powering this client.
        Returns:
        The pipeline.
      • generateSas

        public String generateSas​(ShareServiceSasSignatureValues shareServiceSasSignatureValues)
        Generates a service SAS for the file using the specified 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 = new ShareFileSasPermission().setReadPermission(true);
        
         ShareServiceSasSignatureValues values = new ShareServiceSasSignatureValues(expiryTime, permission)
             .setStartTime(OffsetDateTime.now());
        
         shareFileClient.generateSas(values); // Client must be authenticated via StorageSharedKeyCredential
         
        Parameters:
        shareServiceSasSignatureValues - ShareServiceSasSignatureValues
        Returns:
        A String representing the SAS query parameters.
      • generateSas

        public String generateSas​(ShareServiceSasSignatureValues shareServiceSasSignatureValues,
                                  com.azure.core.util.Context context)
        Generates a service SAS for the file using the specified 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 = new ShareFileSasPermission().setReadPermission(true);
        
         ShareServiceSasSignatureValues values = new ShareServiceSasSignatureValues(expiryTime, permission)
             .setStartTime(OffsetDateTime.now());
        
         // Client must be authenticated via StorageSharedKeyCredential
         shareFileClient.generateSas(values, new Context("key", "value"));
         
        Parameters:
        shareServiceSasSignatureValues - ShareServiceSasSignatureValues
        context - Additional context that is passed through the code when generating a SAS.
        Returns:
        A String representing the SAS query parameters.