Class S3FileAccessV1

java.lang.Object
dev.jcputney.elearning.parser.impl.access.AbstractS3FileAccess
dev.jcputney.elearning.parser.impl.access.S3FileAccessV1
All Implemented Interfaces:
FileAccess, AutoCloseable

public final class S3FileAccessV1 extends AbstractS3FileAccess
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.
    • S3FileAccessV1

      public S3FileAccessV1(com.amazonaws.services.s3.AmazonS3 s3Client, String bucketName, String rootPath, boolean eagerCache)
      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.
      eagerCache - Whether to eagerly cache all files on initialization.
  • Method Details

    • checkFileExistsOnS3

      protected boolean checkFileExistsOnS3(String path)
      Checks if a file exists on the specified S3 bucket at the given path.
      Specified by:
      checkFileExistsOnS3 in class AbstractS3FileAccess
      Parameters:
      path - The relative path of the file within the S3 bucket.
      Returns:
      true if the file exists on the S3 bucket, false otherwise.
    • getFileSizeOnS3

      protected long getFileSizeOnS3(String path)
      Retrieves the size of a file stored in an S3 bucket.
      Specified by:
      getFileSizeOnS3 in class AbstractS3FileAccess
      Parameters:
      path - The relative path of the file within the S3 bucket.
      Returns:
      The size of the file in bytes, or 0 if the file size cannot be retrieved.
    • listFilesOnS3

      protected List<String> listFilesOnS3(String directoryPath)
      Lists the files in a specified directory path on an S3 bucket. Only files are returned, excluding any directory markers. The result is a list of relative paths, relative to the root path of the bucket (if configured).
      Specified by:
      listFilesOnS3 in class AbstractS3FileAccess
      Parameters:
      directoryPath - The relative directory path within the S3 bucket from which files are to be listed. This path is combined with the root path to form the full S3 key prefix.
      Returns:
      A list of file paths within the specified directory on S3. Returns an empty list if an error occurs or no files are found.
    • getS3ObjectAsBytes

      protected byte[] getS3ObjectAsBytes(String fullPath) throws IOException
      Retrieves the content of a specified S3 object as a byte array.
      Specified by:
      getS3ObjectAsBytes in class AbstractS3FileAccess
      Parameters:
      fullPath - The complete path of the object within the S3 bucket.
      Returns:
      A byte array containing the content of the specified S3 object.
      Throws:
      IOException - If an error occurs while accessing the S3 object or reading its content.
    • getS3ObjectStream

      protected InputStream getS3ObjectStream(String fullPath)
      Retrieves an S3 object's content as an input stream based on the specified S3 object path.
      Specified by:
      getS3ObjectStream in class AbstractS3FileAccess
      Parameters:
      fullPath - The complete path of the object within the S3 bucket.
      Returns:
      An InputStream containing the content of the specified S3 object.
    • detectInternalRootDirectory

      protected String detectInternalRootDirectory(String rootPath)
      Detects the internal root directory based on the specified root path by querying the S3 bucket for common prefixes. If there is exactly one common prefix, it is considered the internal root directory; otherwise, the original root path is returned.
      Specified by:
      detectInternalRootDirectory in class AbstractS3FileAccess
      Parameters:
      rootPath - The root path within the S3 bucket to evaluate for an internal root directory.
      Returns:
      The detected internal root directory if a single common prefix is found, or the original root path if no single common prefix is identified or an error occurs.
    • getInputStreamWrapper

      protected InputStream getInputStreamWrapper(InputStream stream, long fileSize)
      Wraps the provided InputStream without modification. This implementation does not support progress listeners and simply returns the input stream as-is.
      Specified by:
      getInputStreamWrapper in class AbstractS3FileAccess
      Parameters:
      stream - The input stream to be wrapped.
      fileSize - The size of the file represented by the input stream, in bytes.
      Returns:
      The same input stream that was provided, unmodified.