DataLakeDirectoryClient Class
- java.
lang. Object - com.
azure. storage. file. datalake. DataLakePathClient - com.
azure. storage. file. datalake. DataLakeDirectoryClient
- com.
- com.
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(String directoryName).
Please refer to the Azure Docs for more information.
Method Summary
Methods inherited from DataLakePathClient
Methods inherited from java.lang.Object
Method Details
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:
Returns:
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:
Returns:
createFileIfNotExists
public DataLakeFileClient createFileIfNotExists(String fileName)
Creates a new file within a directory if it does not exist. For more information, see the Azure Docs.
Code Samples
DataLakeFileClient fileClient = client.createFileIfNotExists(fileName);
Parameters:
Returns:
createFileIfNotExistsWithResponse
public Response
Creates a new file within a directory if it does not exist. For more information, see the Azure Docs.
Code Samples
PathHttpHeaders headers = new PathHttpHeaders().setContentLanguage("en-US").setContentType("binary");
String permissions = "permissions";
String umask = "umask";
DataLakePathCreateOptions options = new DataLakePathCreateOptions()
.setPermissions(permissions)
.setUmask(umask)
.setPathHttpHeaders(headers)
.setMetadata(Collections.singletonMap("metadata", "value"));
Response<DataLakeFileClient> response = client.createFileIfNotExistsWithResponse(fileName, options, timeout,
new Context(key1, value1));
if (response.getStatusCode() == 409) {
System.out.println("Already existed.");
} else {
System.out.printf("Create completed with status %d%n", response.getStatusCode());
}
Parameters:
Returns:
createFileWithResponse
public Response
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);
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
String permissions = "permissions";
String umask = "umask";
String owner = "rwx";
String group = "r--";
String leaseId = CoreUtils.randomUuid().toString();
Integer duration = 15;
DataLakePathCreateOptions options = new DataLakePathCreateOptions()
.setPermissions(permissions)
.setUmask(umask)
.setOwner(owner)
.setGroup(group)
.setPathHttpHeaders(httpHeaders)
.setRequestConditions(requestConditions)
.setMetadata(metadata)
.setProposedLeaseId(leaseId)
.setLeaseDuration(duration);
Response<DataLakeFileClient> newFileClient = client.createFileWithResponse(fileName, options, timeout,
new Context(key1, value1));
Parameters:
Returns:
createFileWithResponse
public Response
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:
Returns:
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:
Returns:
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:
Returns:
createSubdirectoryIfNotExists
public DataLakeDirectoryClient createSubdirectoryIfNotExists(String subdirectoryName)
Creates a new sub-directory if it does not exist within a directory. For more information, see the Azure Docs.
Code Samples
DataLakeDirectoryClient directoryClient = client.createSubdirectoryIfNotExists(directoryName);
Parameters:
Returns:
createSubdirectoryIfNotExistsWithResponse
public Response
Creates a new sub-directory within a directory if it does not exist. For more information, see the Azure Docs.
Code Samples
PathHttpHeaders headers = new PathHttpHeaders()
.setContentLanguage("en-US")
.setContentType("binary");
String permissions = "permissions";
String umask = "umask";
DataLakePathCreateOptions options = new DataLakePathCreateOptions()
.setPermissions(permissions)
.setUmask(umask)
.setPathHttpHeaders(headers)
.setMetadata(Collections.singletonMap("metadata", "value"));
Response<DataLakeDirectoryClient> response = client.createSubdirectoryIfNotExistsWithResponse(directoryName,
options, timeout, new Context(key1, value1));
if (response.getStatusCode() == 409) {
System.out.println("Already existed.");
} else {
System.out.printf("Create completed with status %d%n", response.getStatusCode());
}
Parameters:
Returns:
createSubdirectoryWithResponse
public Response
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);
Map<String, String> metadata = Collections.singletonMap("metadata", "value");
String permissions = "permissions";
String umask = "umask";
String owner = "rwx";
String group = "r--";
String leaseId = CoreUtils.randomUuid().toString();
Integer duration = 15;
DataLakePathCreateOptions options = new DataLakePathCreateOptions()
.setPermissions(permissions)
.setUmask(umask)
.setOwner(owner)
.setGroup(group)
.setPathHttpHeaders(httpHeaders)
.setRequestConditions(requestConditions)
.setMetadata(metadata)
.setProposedLeaseId(leaseId)
.setLeaseDuration(duration);
Response<DataLakeDirectoryClient> newDirectoryClient = client.createSubdirectoryWithResponse(directoryName,
options, timeout, new Context(key1, value1));
Parameters:
Returns:
createSubdirectoryWithResponse
public Response
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:
Returns:
delete
public void delete()
Deletes a directory.
Code Samples
client.delete();
System.out.println("Delete request completed");
For more information see the Azure Docs
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:
deleteFileIfExists
public boolean deleteFileIfExists(String fileName)
Deletes the specified file in the directory if it exists. For more information see the Azure Docs.
Code Samples
boolean result = client.deleteFileIfExists(fileName);
System.out.println("Delete request completed: " + result);
Parameters:
Returns:
true
if the file is successfully deleted, false
if the file does not exist.deleteFileIfExistsWithResponse
public Response
Deletes the specified file in the directory if it exists. For more information see the Azure Docs.
Code Samples
DataLakeRequestConditions requestConditions = new DataLakeRequestConditions()
.setLeaseId(leaseId);
DataLakePathDeleteOptions options = new DataLakePathDeleteOptions().setIsRecursive(false)
.setRequestConditions(requestConditions);
Response<Boolean> response = client.deleteFileIfExistsWithResponse(fileName, options, timeout,
new Context(key1, value1));
if (response.getStatusCode() == 404) {
System.out.println("Does not exist.");
} else {
System.out.printf("Delete completed with status %d%n", response.getStatusCode());
}
Parameters:
Returns:
deleteFileWithResponse
public Response
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:
Returns:
deleteIfExists
public boolean deleteIfExists()
Deletes a directory if it exists.
Code Samples
boolean result = client.deleteIfExists();
System.out.println("Delete request completed: " + result);
For more information see the Azure Docs
Overrides:
DataLakeDirectoryClient.deleteIfExists()Returns:
true
if directory is successfully deleted, false
if directory does not exist.deleteIfExistsWithResponse
public Response
Deletes a directory if it exists.
Code Samples
DataLakeRequestConditions requestConditions = new DataLakeRequestConditions()
.setLeaseId(leaseId);
boolean recursive = false; // Default value
DataLakePathDeleteOptions options = new DataLakePathDeleteOptions().setIsRecursive(recursive)
.setRequestConditions(requestConditions);
Response<Boolean> response = client.deleteIfExistsWithResponse(options, timeout, new Context(key1, value1));
if (response.getStatusCode() == 404) {
System.out.println("Does not exist.");
} else {
System.out.printf("Delete completed with status %d%n", response.getStatusCode());
}
For more information see the Azure Docs
Overrides:
DataLakeDirectoryClient.deleteIfExistsWithResponse(DataLakePathDeleteOptions options, Duration timeout, Context context)Parameters:
Returns:
deleteRecursively
public void deleteRecursively()
Recursively deletes a directory and all contents within the directory.
Code Samples
client.deleteRecursively();
System.out.println("Delete request completed");
For more information see the Azure Docs
deleteRecursivelyWithResponse
public Response
Recursively deletes a directory and all contents within the directory.
Code Samples
DataLakeRequestConditions deleteRequestConditions = new DataLakeRequestConditions()
.setLeaseId(leaseId);
client.deleteRecursivelyWithResponse(deleteRequestConditions, timeout, new Context(key1, value1));
System.out.println("Delete request completed");
For more information see the Azure Docs
Parameters:
Returns:
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:
deleteSubdirectoryIfExists
public boolean deleteSubdirectoryIfExists(String subdirectoryName)
Deletes the specified sub-directory in the directory if it exists. For more information see the Azure Docs.
Code Samples
boolean result = client.deleteSubdirectoryIfExists(directoryName);
System.out.println("Delete request completed: " + result);
Parameters:
Returns:
true
if subdirectory is successfully deleted, false
if subdirectory does not exist.deleteSubdirectoryIfExistsWithResponse
public Response
Deletes the specified subdirectory in the directory if it exists. For more information see the Azure Docs.
Code Samples
DataLakeRequestConditions requestConditions = new DataLakeRequestConditions()
.setLeaseId(leaseId);
boolean recursive = false; // Default value
DataLakePathDeleteOptions options = new DataLakePathDeleteOptions().setIsRecursive(recursive)
.setRequestConditions(requestConditions);
Response<Boolean> response = client.deleteSubdirectoryIfExistsWithResponse(directoryName, options,
timeout, new Context(key1, value1));
if (response.getStatusCode() == 404) {
System.out.println("Does not exist.");
} else {
System.out.printf("Delete completed with status %d%n", response.getStatusCode());
}
Parameters:
Returns:
deleteSubdirectoryWithResponse
public Response
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:
Returns:
deleteWithResponse
public Response
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:
Returns:
getCustomerProvidedKeyClient
public DataLakeDirectoryClient getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)
Creates a new DataLakeDirectoryClient with the specified customerProvidedKey
.
Overrides:
DataLakeDirectoryClient.getCustomerProvidedKeyClient(CustomerProvidedKey customerProvidedKey)Parameters:
null
to use no customer provided key.
Returns:
customerProvidedKey
.getDirectoryName
public String getDirectoryName()
Gets the name of this directory, not including its full path.
Returns:
getDirectoryPath
public String getDirectoryPath()
Gets the path of this directory, not including the name of the resource itself.
Returns:
getDirectoryUrl
public String getDirectoryUrl()
Gets the URL of the directory represented by this client on the Data Lake service.
Returns:
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:
String
representing the name of the file.
Code Samples
DataLakeFileClient dataLakeFileClient = client.getFileClient(fileName);
Returns:
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:
String
representing the name of the sub-directory.
Code Samples
DataLakeDirectoryClient dataLakeDirectoryClient = client.getSubdirectoryClient(directoryName);
Returns:
listPaths
public PagedIterable
Returns a lazy loaded list of files/directories in this directory. The returned PagedIterable<T> 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:
listPaths
public PagedIterable
Returns a lazy loaded list of files/directories in this directory. The returned PagedIterable<T> 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:
Returns:
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:
null
for the current file system.
Returns:
renameWithResponse
public Response
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:
null
for the current file system.
Returns:
Applies to
Azure SDK for Java