Class S3FileAccessV2
java.lang.Object
dev.jcputney.elearning.parser.impl.S3FileAccessV2
- All Implemented Interfaces:
FileAccess
Optimized implementation of FileAccess using AWS S3 SDK v2 with batch operations, streaming
support, and intelligent caching.
-
Constructor Summary
ConstructorsConstructorDescriptionS3FileAccessV2(software.amazon.awssdk.services.s3.S3Client s3Client, String bucketName, String rootPath) Constructs an optimized S3FileAccessV2 instance with the specified S3 client and bucket name. -
Method Summary
Modifier and TypeMethodDescriptionvoidClear all caches - useful for testing or when bucket contents change.fileExistsBatch(List<String> paths) Batch check if multiple files exist - much more efficient for module parsing.booleanfileExistsInternal(String path) Checks if a file exists at the specified path with caching.Retrieves the current statistics of the internal caches used by the system.Gets the contents of a file as an InputStream with intelligent streaming/caching.getFileContentsInternal(String path, StreamingProgressListener progressListener) Gets the contents of a file as an InputStream with optional progress tracking.Determines the internal root directory within the S3 bucket with lazy initialization.listFilesInternal(String directoryPath) Lists the files in the specified directory path with caching and pagination support.voidPrefetch common module files in parallel for faster subsequent access.voidshutdown()Shutdown the executor service when the instance is no longer needed.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
fileExists, fullPath, getFileContents, getRootPath, listFiles
-
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
Checks if a file exists at the specified path with caching.- Specified by:
fileExistsInternalin interfaceFileAccess- Parameters:
path- The path of the file to check (guaranteed to be non-null).- Returns:
- True if the file exists, false otherwise.
-
fileExistsBatch
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
Lists the files in the specified directory path with caching and pagination support.- Specified by:
listFilesInternalin interfaceFileAccess- 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
Gets the contents of a file as an InputStream with intelligent streaming/caching.- Specified by:
getFileContentsInternalin interfaceFileAccess- 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
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
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.
-