Class ClasspathFileAccess
java.lang.Object
dev.jcputney.elearning.parser.impl.access.ClasspathFileAccess
- All Implemented Interfaces:
FileAccess
Implementation of
FileAccess that reads files from the classpath, allowing testing of
modules stored in the resources directory without needing actual filesystem access.-
Constructor Summary
ConstructorsConstructorDescriptionClasspathFileAccess(String rootPath) Constructs a ClasspathFileAccess instance with the specified root path. -
Method Summary
Modifier and TypeMethodDescriptionbooleanfileExistsInternal(String path) Checks if a file exists on the classpath at the given path.Retrieves the contents of a file as an InputStream from the classpath.Retrieves the root path used for file access.longGets the total size of all files accessible from the classpath.listFilesInternal(String directoryPath) Lists all files within a specified directory path on the classpath.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.jcputney.elearning.parser.api.FileAccess
clearCaches, fileExists, fileExistsBatch, fullPath, getAllFiles, getFileContents, listFiles, prefetchCommonFiles
-
Constructor Details
-
ClasspathFileAccess
Constructs a ClasspathFileAccess instance with the specified root path.- Parameters:
rootPath- The root path for file access.
-
-
Method Details
-
fileExistsInternal
Checks if a file exists on the classpath at the given path.- Specified by:
fileExistsInternalin interfaceFileAccess- Parameters:
path- The path to check (guaranteed to be non-null).- Returns:
- True if the file exists on the classpath, false otherwise.
-
listFilesInternal
Lists all files within a specified directory path on the classpath.- Specified by:
listFilesInternalin interfaceFileAccess- Parameters:
directoryPath- The directory to list files from (guaranteed to be non-null).- Returns:
- A list of file paths within the specified directory.
- Throws:
IOException- If there's an issue accessing the files.
-
getFileContentsInternal
Retrieves the contents of a file as an InputStream from the classpath.- Specified by:
getFileContentsInternalin interfaceFileAccess- 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.
-
getTotalSize
Gets the total size of all files accessible from the classpath.Note: This implementation returns -1 as classpath resources don't have a reliable way to determine file sizes without reading the entire content.
- Specified by:
getTotalSizein interfaceFileAccess- Returns:
- -1 to indicate size calculation is not supported for classpath resources
- Throws:
IOException- if there's an error accessing resources
-
getRootPath
Retrieves the root path used for file access.- Specified by:
getRootPathin interfaceFileAccess- Returns:
- The root path as a string.
-