Repository navigation
Expand file tree
/
Copy pathPathHandler.java
More file actions
76 lines (70 loc) · 3.05 KB
/
Copy pathPathHandler.java
File metadata and controls
76 lines (70 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package helper_classes;
import driver.IShellState;
import file_system.Directory;
import file_system.File;
import file_system.VirtualFileSystem;
import file_system.FileSystemObject;
/**
* This is class finds files and directories related to the shell given path
*/
public class PathHandler {
/**
* This method is used when trying to create or access some file or directory
* with the path. Gets the directory from which the file/directory is
* attempted to be created/accessed from and its name
* @param shellState holds state of the program including root directory and
* current directory
* @param path is the specified path that indicates which file/directory is
* attempted to be created/accessed
* @return a tuple that holds directory from which the file/directory is
* attempted to be created/accessed from and its name
* @throws Exception if the given path is invalid
*/
public static DirectoryFileNameTuple getDirectoryAndFileName
(IShellState shellState, String path) throws Exception {
VirtualFileSystem fs = shellState.getFileSystem();
return fs.getDirectoryAndFileName(shellState.getCurrentDir(), path);
}
/**
* This method is used when trying to access some file system object such as
* file or directory with the path.
* @param shellState holds state of the program including root directory and
* current directory
* @param path is the specified path that indicates which file/directory is
* attempted to be accessed
* @return the file system object indicated by path
* @throws Exception if the object does not exist at given path
*/
public static FileSystemObject getFileSystemObject
(IShellState shellState, String path) throws Exception {
VirtualFileSystem fs = shellState.getFileSystem();
return fs.getFileSystemObject(shellState.getCurrentDir(), path);
}
/**
* Get the file specified by path
* @param shellState holds state of the program including root directory and
* current directory
* @param path is the specified path(complete or relative)
* @return path described by path
* @throws Exception if the path specified object at this path is not a file
*/
public static File getFileByPath
(IShellState shellState, String path) throws Exception {
VirtualFileSystem fs = shellState.getFileSystem();
return fs.getFileByPath(shellState.getCurrentDir(), path);
}
/**
* Get the directory specified by path
* @param shellState holds state of the program including root directory and
* current directory
* @param path is the specified path(complete or relative)
* @return directory described by path
* @throws Exception if the path specified object at this path is not a
* directory
*/
public static Directory getDirectoryByPath
(IShellState shellState, String path) throws Exception {
VirtualFileSystem fs = shellState.getFileSystem();
return fs.getDirectoryByPath(shellState.getCurrentDir(), path);
}
}