Interface FileAccess
- All Known Implementing Classes:
CachedFileAccess,ClasspathFileAccess,LocalFileAccess,ResourceUtils.SafeFileAccess,S3FileAccessV1,S3FileAccessV2,ZipFileAccess
public interface FileAccess
An interface for accessing files within a package or directory. This interface is a core
component of the module parser architecture, providing a unified way to access files regardless
of their storage mechanism (local file system, ZIP archive, cloud storage, etc.).
Implementations of this interface should provide methods for:
- Checking if a file exists
- Listing files within a directory
- Retrieving file contents as an InputStream
An implementation of this interface should be provided to parsers for reading files within
a module package. The default implementation is the
LocalFileAccess class, but other implementations
are available for different storage mechanisms:
ZipFileAccess- For accessing files in ZIP archives- S3FileAccess implementations - For accessing files in AWS S3 buckets
This interface follows the Strategy pattern, allowing different file access strategies to be interchanged without affecting the parsers that use them.
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanfileExists(String path) Checks if a file exists at the given path.booleanfileExistsInternal(String path) Internal method to check if a file exists at the given path.default StringConstructs the full path for the given relative or absolute path.default InputStreamgetFileContents(String path) Retrieves the contents of a file as an InputStream.Internal method to retrieve the contents of a file as an InputStream.Retrieves the root path used for file access.Lists all files within a specified directory path.listFilesInternal(String directoryPath) Internal method to list all files within a specified directory path.
-
Method Details
-
getRootPath
String getRootPath()Retrieves the root path used for file access.- Returns:
- The root path used for file access.
-
fileExists
Checks if a file exists at the given path.- Parameters:
path- The path to check.- Returns:
- True if the file exists, false otherwise.
- Throws:
IllegalArgumentException- if path is null
-
fileExistsInternal
Internal method to check if a file exists at the given path. This method is called by the default implementation offileExists(String).- Parameters:
path- The path to check (guaranteed to be non-null).- Returns:
- True if the file exists, false otherwise.
-
listFiles
Lists all files within a specified directory path.- Parameters:
directoryPath- The directory to list files from.- Returns:
- A list of file paths within the directory.
- Throws:
IOException- if there's an error accessing the directory or listing its contents.IllegalArgumentException- if directoryPath is null
-
listFilesInternal
Internal method to list all files within a specified directory path. This method is called by the default implementation oflistFiles(String).- Parameters:
directoryPath- The directory to list files from (guaranteed to be non-null).- Returns:
- A list of file paths within the directory.
- Throws:
IOException- if there's an error accessing the directory or listing its contents.
-
getFileContents
Retrieves the contents of a file as an InputStream.- Parameters:
path- The path to retrieve contents from.- Returns:
- An InputStream of the file contents.
- Throws:
IOException- if the file can't be read.IllegalArgumentException- if path is null
-
getFileContentsInternal
Internal method to retrieve the contents of a file as an InputStream. This method is called by the default implementation ofgetFileContents(String).- Parameters:
path- The path to retrieve contents from (guaranteed to be non-null).- Returns:
- An InputStream of the file contents.
- Throws:
IOException- if the file can't be read.
-
fullPath
Constructs the full path for the given relative or absolute path.This method handles path normalization according to the following rules:
- If the path starts with a forward slash ("/"), it is treated as an absolute path and the leading "/" is removed.
- Otherwise, the path is treated as relative and the rootPath is prefixed to form the full path.
- If rootPath is empty, the relative path is returned as-is without any prefix.
This method is used internally by implementations to normalize paths before accessing files.
- Parameters:
path- The relative or absolute path for which the full path is to be generated.- Returns:
- The constructed full path as a string.
- Throws:
IllegalArgumentException- if path is null
-