Class S3FileAccessV1

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

public class S3FileAccessV1 extends Object implements FileAccess
Optimized implementation of FileAccess using AWS S3 SDK v1 with batch operations, streaming support, and intelligent caching.
  • Constructor Details

    • S3FileAccessV1

      public S3FileAccessV1(com.amazonaws.services.s3.AmazonS3 s3Client, String bucketName, String rootPath)
      Constructs an optimized S3FileAccessV1 instance with the specified S3 client and bucket name.
      Parameters:
      s3Client - The S3 client to use for accessing files.
      bucketName - The name of the S3 bucket to access.
      rootPath - The root path of the S3 bucket to access.
  • Method Details

    • fileExistsInternal

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

      public Map<String,Boolean> fileExistsBatch(List<String> paths)
      Batch check if multiple files exist - much more efficient for module parsing.
      Parameters:
      paths - List of file paths to check
      Returns:
      Map of path to existence boolean
    • prefetchCommonFiles

      public void prefetchCommonFiles()
      Prefetch common module files in parallel for faster subsequent access.
    • listFilesInternal

      public List<String> listFilesInternal(String directoryPath) throws IOException
      Lists the files in the specified directory path with caching and pagination support.
      Specified by:
      listFilesInternal in interface FileAccess
      Parameters:
      directoryPath - The path of the directory to list files from (guaranteed to be non-null).
      Returns:
      A list of file paths in the specified directory.
      Throws:
      IOException - if there's an error accessing the directory or listing its contents.
    • getFileContentsInternal

      public InputStream getFileContentsInternal(String path) throws IOException
      Gets the contents of a file as an InputStream with intelligent streaming/caching.
      Specified by:
      getFileContentsInternal in interface FileAccess
      Parameters:
      path - The path of the file to get contents from (guaranteed to be non-null).
      Returns:
      An InputStream containing the file contents.
      Throws:
      IOException - if the file can't be read.
    • getInternalRootDirectory

      public String getInternalRootDirectory()
      Determines the internal root directory within the S3 bucket with lazy initialization.
      Returns:
      The detected internal root directory or the original path if none is detected.
    • clearCaches

      public void clearCaches()
      Clear all caches - useful for testing or when bucket contents change.
    • getCacheStats

      public Map<String,Integer> getCacheStats()
      Retrieves statistics about various internal caches used in the class.
      Returns:
      A map where the keys are the cache names (e.g., "fileExistsCache", "directoryListCache", etc.) and the values are the respective sizes of these caches.
    • shutdown

      public void shutdown()
      Shutdown the executor service when the instance is no longer needed.