Class DataLakeDirectoryClient


  • public class DataLakeDirectoryClient
    extends DataLakePathClient
    This class provides a client that contains directory operations for Azure Storage Data Lake. Operations provided by this client include creating a directory, deleting a directory, renaming a directory, setting metadata and http headers, setting and retrieving access control, getting properties and creating and deleting files and subdirectories.

    This client is instantiated through DataLakePathClientBuilder or retrieved via getDirectoryClient.

    Please refer to the Azure Docs for more information.

    • Method Detail

      • getDirectoryUrl

        public String getDirectoryUrl()
        Gets the URL of the directory represented by this client on the Data Lake service.
        Returns:
        the URL.
      • getDirectoryPath

        public String getDirectoryPath()
        Gets the path of this directory, not including the name of the resource itself.
        Returns:
        The path of the directory.
      • getDirectoryName

        public String getDirectoryName()
        Gets the name of this directory, not including its full path.
        Returns:
        The name of the directory.
      • delete

        public void delete()
        Deletes a directory.

        Code Samples

         client.delete();
         System.out.println("Delete request completed");
         

        For more information see the Azure Docs

      • deleteWithResponse

        public com.azure.core.http.rest.Response<Void> deleteWithResponse​(boolean recursive,
                                                                          DataLakeRequestConditions requestConditions,
                                                                          Duration timeout,
                                                                          com.azure.core.util.Context context)
        Deletes a directory.

        Code Samples

         DataLakeRequestConditions requestConditions = new DataLakeRequestConditions()
             .setLeaseId(leaseId);
         boolean recursive = false; // Default value
        
         client.deleteWithResponse(recursive, requestConditions, timeout, new Context(key1, value1));
         System.out.println("Delete request completed");
         

        For more information see the Azure Docs

        Parameters:
        recursive - Whether or not to delete all paths beneath the directory.
        requestConditions - DataLakeRequestConditions
        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:
        A reactive response signalling completion.
      • getFileClient

        public DataLakeFileClient getFileClient​(String fileName)
        Initializes a new DataLakeFileClient object by concatenating fileName to the end of DataLakeDirectoryClient's URL. The new DataLakeFileClient uses the same request policy pipeline as the DataLakeDirectoryClient.
        Parameters:
        fileName - A String representing the name of the file.

        Code Samples

         DataLakeFileClient dataLakeFileClient = client.getFileClient(fileName);
         
        Returns:
        A new DataLakeFileClient object which references the file with the specified name in this directory.
      • createFile

        public DataLakeFileClient createFile​(String fileName)
        Creates a new file within a directory. By default this method will not overwrite an existing file. For more information, see the Azure Docs.

        Code Samples

         DataLakeFileClient fileClient = client.createFile(fileName);
         
        Parameters:
        fileName - Name of the file to create.
        Returns:
        A DataLakeFileClient used to interact with the file created.
      • createFile

        public DataLakeFileClient createFile​(String fileName,
                                             boolean overwrite)
        Creates a new file within a directory. For more information, see the Azure Docs.

        Code Samples

         boolean overwrite = false; /* Default value. */
         DataLakeFileClient fClient = client.createFile(fileName, overwrite);
         
        Parameters:
        fileName - Name of the file to create.
        overwrite - Whether or not to overwrite, should a file exist.
        Returns:
        A DataLakeFileClient used to interact with the file created.
      • createFileWithResponse

        public com.azure.core.http.rest.Response<DataLakeFileClient> createFileWithResponse​(String fileName,
                                                                                            String permissions,
                                                                                            String umask,
                                                                                            PathHttpHeaders headers,
                                                                                            Map<String,​String> metadata,
                                                                                            DataLakeRequestConditions requestConditions,
                                                                                            Duration timeout,
                                                                                            com.azure.core.util.Context context)
        Creates a new file within a directory. If a file with the same name already exists, the file will be overwritten. For more information, see the Azure Docs.

        Code Samples

         PathHttpHeaders httpHeaders = new PathHttpHeaders()
             .setContentLanguage("en-US")
             .setContentType("binary");
         DataLakeRequestConditions requestConditions = new DataLakeRequestConditions()
             .setLeaseId(leaseId);
         String permissions = "permissions";
         String umask = "umask";
         Response<DataLakeFileClient> newFileClient = client.createFileWithResponse(fileName, permissions, umask, httpHeaders,
             Collections.singletonMap("metadata", "value"), requestConditions,
             timeout, new Context(key1, value1));
         
        Parameters:
        fileName - Name of the file to create.
        permissions - POSIX access permissions for the file owner, the file owning group, and others.
        umask - Restricts permissions of the file to be created.
        headers - PathHttpHeaders
        metadata - Metadata to associate with the file. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.
        requestConditions - DataLakeRequestConditions
        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:
        A Response whose value contains the DataLakeFileClient used to interact with the file created.
      • deleteFile

        public void deleteFile​(String fileName)
        Deletes the specified file in the directory. If the file doesn't exist the operation fails. For more information see the Azure Docs.

        Code Samples

         client.deleteFile(fileName);
         System.out.println("Delete request completed");
         
        Parameters:
        fileName - Name of the file to delete.
      • deleteFileWithResponse

        public com.azure.core.http.rest.Response<Void> deleteFileWithResponse​(String fileName,
                                                                              DataLakeRequestConditions requestConditions,
                                                                              Duration timeout,
                                                                              com.azure.core.util.Context context)
        Deletes the specified file in the directory. If the file doesn't exist the operation fails. For more information see the Azure Docs.

        Code Samples

         DataLakeRequestConditions requestConditions = new DataLakeRequestConditions()
             .setLeaseId(leaseId);
        
         client.deleteFileWithResponse(fileName, requestConditions, timeout, new Context(key1, value1));
         System.out.println("Delete request completed");
         
        Parameters:
        fileName - Name of the file to delete.
        requestConditions - DataLakeRequestConditions
        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:
        A response containing status code and HTTP headers
      • getSubdirectoryClient

        public DataLakeDirectoryClient getSubdirectoryClient​(String subdirectoryName)
        Initializes a new DataLakeDirectoryClient object by concatenating directoryName to the end of DataLakeDirectoryClient's URL. The new DataLakeDirectoryClient uses the same request policy pipeline as the DataLakeDirectoryClient.
        Parameters:
        subdirectoryName - A String representing the name of the sub-directory.

        Code Samples

         DataLakeDirectoryClient dataLakeDirectoryClient = client.getSubdirectoryClient(directoryName);
         
        Returns:
        A new DataLakeDirectoryClient object which references the sub-directory with the specified name in this directory
      • createSubdirectory

        public DataLakeDirectoryClient createSubdirectory​(String subdirectoryName)
        Creates a new sub-directory within a directory. By default this method will not overwrite an existing sub-directory. For more information, see the Azure Docs.

        Code Samples

         DataLakeDirectoryClient directoryClient = client.createSubdirectory(directoryName);
         
        Parameters:
        subdirectoryName - Name of the sub-directory to create.
        Returns:
        A DataLakeDirectoryClient used to interact with the sub-directory created.
      • createSubdirectory

        public DataLakeDirectoryClient createSubdirectory​(String subdirectoryName,
                                                          boolean overwrite)
        Creates a new sub-directory within a directory. For more information, see the Azure Docs.

        Code Samples

         boolean overwrite = false; /* Default value. */
         DataLakeDirectoryClient dClient = client.createSubdirectory(fileName, overwrite);
         
        Parameters:
        subdirectoryName - Name of the sub-directory to create.
        overwrite - Whether or not to overwrite, should the sub-directory exist.
        Returns:
        A DataLakeDirectoryClient used to interact with the sub-directory created.
      • createSubdirectoryWithResponse

        public com.azure.core.http.rest.Response<DataLakeDirectoryClient> createSubdirectoryWithResponse​(String subdirectoryName,
                                                                                                         String permissions,
                                                                                                         String umask,
                                                                                                         PathHttpHeaders headers,
                                                                                                         Map<String,​String> metadata,
                                                                                                         DataLakeRequestConditions requestConditions,
                                                                                                         Duration timeout,
                                                                                                         com.azure.core.util.Context context)
        Creates a new sub-directory within a directory. If a sub-directory with the same name already exists, the sub-directory will be overwritten. For more information, see the Azure Docs.

        Code Samples

         PathHttpHeaders httpHeaders = new PathHttpHeaders()
             .setContentLanguage("en-US")
             .setContentType("binary");
         DataLakeRequestConditions requestConditions = new DataLakeRequestConditions()
             .setLeaseId(leaseId);
         String permissions = "permissions";
         String umask = "umask";
         Response<DataLakeDirectoryClient> newDirectoryClient = client.createSubdirectoryWithResponse(directoryName,
             permissions, umask, httpHeaders, Collections.singletonMap("metadata", "value"), requestConditions, timeout,
             new Context(key1, value1));
         
        Parameters:
        subdirectoryName - Name of the sub-directory to create.
        permissions - POSIX access permissions for the sub-directory owner, the sub-directory owning group, and others.
        umask - Restricts permissions of the sub-directory to be created.
        headers - PathHttpHeaders
        metadata - Metadata to associate with the resource. If there is leading or trailing whitespace in any metadata key or value, it must be removed or encoded.
        requestConditions - DataLakeRequestConditions
        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:
        A Response whose value contains a DataLakeDirectoryClient used to interact with the sub-directory created.
      • deleteSubdirectory

        public void deleteSubdirectory​(String subdirectoryName)
        Deletes the specified sub-directory in the directory. If the sub-directory doesn't exist or is not empty the operation fails. For more information see the Azure Docs.

        Code Samples

         client.deleteSubdirectory(directoryName);
         System.out.println("Delete request completed");
         
        Parameters:
        subdirectoryName - Name of the sub-directory to delete.
      • deleteSubdirectoryWithResponse

        public com.azure.core.http.rest.Response<Void> deleteSubdirectoryWithResponse​(String subdirectoryName,
                                                                                      boolean recursive,
                                                                                      DataLakeRequestConditions requestConditions,
                                                                                      Duration timeout,
                                                                                      com.azure.core.util.Context context)
        Deletes the specified sub-directory in the directory. If the sub-directory doesn't exist or is not empty the operation fails. For more information see the Azure Docs.

        Code Samples

         DataLakeRequestConditions requestConditions = new DataLakeRequestConditions()
             .setLeaseId(leaseId);
         boolean recursive = false; // Default value
        
         client.deleteSubdirectoryWithResponse(directoryName, recursive, requestConditions, timeout,
             new Context(key1, value1));
         System.out.println("Delete request completed");
         
        Parameters:
        subdirectoryName - Name of the sub-directory to delete.
        recursive - Whether or not to delete all paths beneath the sub-directory.
        requestConditions - DataLakeRequestConditions
        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:
        A response containing status code and HTTP headers
      • rename

        public DataLakeDirectoryClient rename​(String destinationFileSystem,
                                              String destinationPath)
        Moves the directory to another location within the file system. For more information see the Azure Docs.

        Code Samples

         DataLakeDirectoryClient renamedClient = client.rename(fileSystemName, destinationPath);
         System.out.println("Directory Client has been renamed");
         
        Parameters:
        destinationFileSystem - The file system of the destination within the account. null for the current file system.
        destinationPath - Relative path from the file system to rename the directory to, excludes the file system name. For example if you want to move a directory with fileSystem = "myfilesystem", path = "mydir/mysubdir" to another path in myfilesystem (ex: newdir) then set the destinationPath = "newdir"
        Returns:
        A DataLakeDirectoryClient used to interact with the new directory created.
      • renameWithResponse

        public com.azure.core.http.rest.Response<DataLakeDirectoryClient> renameWithResponse​(String destinationFileSystem,
                                                                                             String destinationPath,
                                                                                             DataLakeRequestConditions sourceRequestConditions,
                                                                                             DataLakeRequestConditions destinationRequestConditions,
                                                                                             Duration timeout,
                                                                                             com.azure.core.util.Context context)
        Moves the directory to another location within the file system. For more information, see the Azure Docs.

        Code Samples

         DataLakeRequestConditions sourceRequestConditions = new DataLakeRequestConditions()
             .setLeaseId(leaseId);
         DataLakeRequestConditions destinationRequestConditions = new DataLakeRequestConditions();
        
         DataLakeDirectoryClient newRenamedClient = client.renameWithResponse(fileSystemName, destinationPath,
             sourceRequestConditions, destinationRequestConditions, timeout, new Context(key1, value1)).getValue();
         System.out.println("Directory Client has been renamed");
         
        Parameters:
        destinationFileSystem - The file system of the destination within the account. null for the current file system.
        destinationPath - Relative path from the file system to rename the directory to, excludes the file system name. For example if you want to move a directory with fileSystem = "myfilesystem", path = "mydir/mysubdir" to another path in myfilesystem (ex: newdir) then set the destinationPath = "newdir"
        sourceRequestConditions - DataLakeRequestConditions against the source.
        destinationRequestConditions - DataLakeRequestConditions against the destination.
        timeout - An optional timeout value beyond which a RuntimeException will be raised.
        context - Additional context that is passed through the Http pipeline during the service call.
        Returns:
        A Response whose value that contains a DataLakeDirectoryClient used to interact with the directory created.
      • listPaths

        public com.azure.core.http.rest.PagedIterable<PathItem> listPaths()
        Returns a lazy loaded list of files/directories in this directory. The returned PagedIterable can be consumed while new items are automatically retrieved as needed. For more information, see the Azure Docs.

        Code Samples

         client.listPaths().forEach(path -> System.out.printf("Name: %s%n", path.getName()));
         
        Returns:
        The list of files/directories.
      • listPaths

        public com.azure.core.http.rest.PagedIterable<PathItem> listPaths​(boolean recursive,
                                                                          boolean userPrincipleNameReturned,
                                                                          Integer maxResults,
                                                                          Duration timeout)
        Returns a lazy loaded list of files/directories in this directory. The returned PagedIterable can be consumed while new items are automatically retrieved as needed. For more information, see the Azure Docs.

        Code Samples

         client.listPaths(false, false, 10, timeout)
             .forEach(path -> System.out.printf("Name: %s%n", path.getName()));
         
        Parameters:
        recursive - Specifies if the call should recursively include all paths.
        userPrincipleNameReturned - If "true", the user identity values returned in the x-ms-owner, x-ms-group, and x-ms-acl response headers will be transformed from Azure Active Directory Object IDs to User Principal Names. If "false", the values will be returned as Azure Active Directory Object IDs. The default value is false. Note that group and application Object IDs are not translated because they do not have unique friendly names.
        maxResults - Specifies the maximum number of blobs to return per page, including all BlobPrefix elements. If the request does not specify maxResults or specifies a value greater than 5,000, the server will return up to 5,000 items per page. If iterating by page, the page size passed to byPage methods such as ContinuablePagedIterable.iterableByPage(int) will be preferred over this value.
        timeout - An optional timeout value beyond which a RuntimeException will be raised.
        Returns:
        The list of files/directories.