Class ClasspathFileAccess

java.lang.Object
dev.jcputney.elearning.parser.impl.access.ClasspathFileAccess
All Implemented Interfaces:
FileAccess

public final class ClasspathFileAccess extends Object implements 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 Details

    • ClasspathFileAccess

      public ClasspathFileAccess(String rootPath)
      Constructs a ClasspathFileAccess instance with the specified root path.
      Parameters:
      rootPath - The root path for file access.
  • Method Details

    • fileExistsInternal

      public boolean fileExistsInternal(String path)
      Checks if a file exists on the classpath at the given path.
      Specified by:
      fileExistsInternal in interface FileAccess
      Parameters:
      path - The path to check (guaranteed to be non-null).
      Returns:
      True if the file exists on the classpath, false otherwise.
    • listFilesInternal

      public List<String> listFilesInternal(String directoryPath) throws IOException
      Lists all files within a specified directory path on the classpath.
      Specified by:
      listFilesInternal in interface FileAccess
      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

      public InputStream getFileContentsInternal(String path) throws IOException
      Retrieves the contents of a file as an InputStream from the classpath.
      Specified by:
      getFileContentsInternal in interface FileAccess
      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

      public long getTotalSize() throws IOException
      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:
      getTotalSize in interface FileAccess
      Returns:
      -1 to indicate size calculation is not supported for classpath resources
      Throws:
      IOException - if there's an error accessing resources
    • getRootPath

      public String getRootPath()
      Retrieves the root path used for file access.
      Specified by:
      getRootPath in interface FileAccess
      Returns:
      The root path as a string.