Class S3FileAccessV2

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

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

    • S3FileAccessV2

      public S3FileAccessV2(software.amazon.awssdk.services.s3.S3Client s3Client, String bucketName, String rootPath)
      Constructs an optimized S3FileAccessV2 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 an error occurs while listing files.
    • 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 an error occurs while getting file contents.
    • 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 get contents from (guaranteed to be non-null).
      progressListener - Optional progress listener for tracking large file operations.
      Returns:
      An InputStream containing the file contents.
      Throws:
      IOException - If an error occurs while getting file contents.
    • 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 the current statistics of the internal caches used by the system. Provides size information for each cache, allowing insight into resource usage.
      Returns:
      A map where the key is the name of the cache and the value is the size of the cache. Keys include: - "fileExistsCache": The size of the cache tracking file existence. - "directoryListCache": The size of the cache storing directory listings. - "smallFileCache": The size of the cache storing small files. - "fileSizeCache": The size of the cache storing file size data.
    • shutdown

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