Class S3Utils

java.lang.Object
com.kingsrook.qqq.backend.module.filesystem.s3.utils.S3Utils

public class S3Utils extends Object
Utility methods for working with AWS S3 (or any S3-compatible store), on an AWS SDK v2 S3Client. Actions set the client built by S3ClientFactory from their backend's meta data.
  • Constructor Details

    • S3Utils

      public S3Utils()
  • Method Details

    • listObjectsInBucketMatchingGlob

      public List<S3ObjectSummary> listObjectsInBucketMatchingGlob(String bucketName, String path, String glob) throws QException
      List the objects in an S3 bucket matching a glob, per: https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#getPathMatcher(java.lang.String)
      Throws:
      QException
    • listObjectsInBucketMatchingGlob

      public List<S3ObjectSummary> listObjectsInBucketMatchingGlob(String bucketName, String path, String glob, String requestedPath, AbstractFilesystemTableBackendDetails tableDetails) throws QException
      List the objects in an S3 bucket matching a glob, per: https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#getPathMatcher(java.lang.String) and also - (possibly) apply a file-name filter (based on the table's details).
      Throws:
      QException
    • listObjectsInBucketMatchingGlob

      public List<S3ObjectSummary> listObjectsInBucketMatchingGlob(String bucketName, String path, String glob, String requestedPath, AbstractFilesystemTableBackendDetails tableDetails, Integer maxListedObjects) throws QException
      List the objects in an S3 bucket matching a glob, as above, failing with a FilesystemException (instead of exhausting memory) if more than maxListedObjects objects match. A null maxListedObjects means no cap.
      Throws:
      QException
    • getObjectAsInputStream

      public InputStream getObjectAsInputStream(S3ObjectSummary s3ObjectSummary)
      Get the contents (as an InputStream) for an object in s3
    • writeFile

      public void writeFile(String bucket, String key, byte[] contents, String contentType)
      Write a file
    • deleteObject

      public void deleteObject(String bucketName, String key) throws FilesystemException
      Delete an object (file) from a bucket
      Throws:
      FilesystemException
    • moveObject

      public void moveObject(String bucketName, String source, String destination) throws FilesystemException
      Move an object (file) within a bucket
      Throws:
      FilesystemException
    • setS3Client

      public void setS3Client(software.amazon.awssdk.services.s3.S3Client s3Client)
      Setter for the S3 client.
    • getS3Client

      public software.amazon.awssdk.services.s3.S3Client getS3Client()
      Getter for the S3 client. If none was set, uses the shared client for a default (us-east-1, default credential chain) AWS connection.