Class LocalFileAccess

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

public final class LocalFileAccess extends Object implements FileAccess
Implementation of FileAccess for local file access. This class provides methods to check file existence, list files in a directory, and read file contents.
  • Constructor Details

    • LocalFileAccess

      public LocalFileAccess(String rootPath)
      Constructs a LocalFileAccess instance with the specified root path.
      Parameters:
      rootPath - The root path for file access.
      Throws:
      IllegalArgumentException - if the root path is null or not a valid directory.
  • Method Details

    • fileExistsInternal

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

      public List<String> listFilesInternal(String directoryPath) throws IOException
      Lists all files in the specified directory.
      Specified by:
      listFilesInternal in interface FileAccess
      Parameters:
      directoryPath - The path of the directory to list files from.
      Returns:
      A list of file paths relative to the root path.
      Throws:
      IOException - if an error occurs while listing files.
    • getFileContentsInternal

      public InputStream getFileContentsInternal(String path) throws IOException
      Gets the contents of a file as an InputStream.
      Specified by:
      getFileContentsInternal in interface FileAccess
      Parameters:
      path - The path of the file to read.
      Returns:
      An InputStream for reading the file contents.
      Throws:
      IOException - if an error occurs while reading the file.
    • getFileContentsInternal

      public InputStream getFileContentsInternal(String path, StreamingProgressListener progressListener) throws IOException
      Gets the contents of a file as an InputStream with optional progress tracking.
      Parameters:
      path - The path of the file to read.
      progressListener - Optional progress listener for tracking large file operations.
      Returns:
      An InputStream for reading the file contents.
      Throws:
      IOException - if an error occurs while reading the file.
    • getTotalSize

      public long getTotalSize() throws IOException
      Gets the total size of all files in the module.

      This method recursively walks the directory tree and sums the sizes of all files.

      Specified by:
      getTotalSize in interface FileAccess
      Returns:
      Total size of all files in bytes
      Throws:
      IOException - if there's an error accessing file sizes
    • getRootPath

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