Class S3StorageUtils

java.lang.Object
overit.geocallapp.wfm.ai.bl.processing.utils.S3StorageUtils

public class S3StorageUtils extends Object
  • Constructor Details

    • S3StorageUtils

      public S3StorageUtils()
  • Method Details

    • listBucketObjects

      public static Map<String,String> listBucketObjects(String bucketName, software.amazon.awssdk.services.s3.S3Client s3client)
      This is the method that you want to use to list all object. In the logger you have the info about file's owner and size.
      Parameters:
      bucketName - the unique name of the bucket where you want to list the objects.
      s3client - the client you get with ClientManager.getS3Login();
      Returns:
      a Map with ObjectKey, size + owner
    • listBucketObjects

      public static Map<String,String> listBucketObjects(String bucketName, String objectKey, software.amazon.awssdk.services.s3.S3Client s3client) throws software.amazon.awssdk.services.s3.model.S3Exception
      Throws:
      software.amazon.awssdk.services.s3.model.S3Exception
    • exist

      public static boolean exist(String bucketName, String objectKey, software.amazon.awssdk.services.s3.S3Client s3client) throws software.amazon.awssdk.services.s3.model.S3Exception
      Make a object request that check if the given path, ex. train/file.txt exist or not.
      Parameters:
      bucketName - the name of the bucket
      objectKey - The path in s3 for that object. ex. "folder/folder1/file.txt"
      s3client - the client you built with new Login(..).doS3Login();
      Returns:
      true if the objectKey in is that bucket, false otherwise.
      Throws:
      software.amazon.awssdk.services.s3.model.S3Exception
    • deleteBucketObject

      public static void deleteBucketObject(String bucketName, String objectKey, software.amazon.awssdk.services.s3.S3Client s3Client) throws software.amazon.awssdk.services.s3.model.S3Exception
      Method that delete one object from a bucket
      Parameters:
      bucketName - the name of the bucket
      objectKey - The name of the object, it must also contains the extension, ex. test.txt if you want to delete an object under some folder use: "folder/folder1/file.ext"
      s3Client - the client you get with ClientManager.getS3Login();
      Throws:
      software.amazon.awssdk.services.s3.model.S3Exception
    • putS3Object

      public static String putS3Object(String bucketName, String remoteParent, String localFilePath, software.amazon.awssdk.services.s3.S3Client s3Client) throws software.amazon.awssdk.services.s3.model.S3Exception, IllegalArgumentException
      Method that put a selected object into a bucket, with or without amazon prefix.
      Parameters:
      bucketName - the name of the bucket
      remoteParent - The unique name the object will have in s3, the extension is mandatory, If you wanna upload a file inside a folder/s and keep them also in s3, or you want to create prefix in s3, use: "folder/folder1/file.txt", in amazon you will have: folder/folder1/file.txt.
      localFilePath - The absolute path to the object you want to put in a bucket, ex.C:\\..test.txt
      s3Client - the client you get with ClientManager.getS3Login();
      Returns:
      s3 key where object is been uploaded
      Throws:
      software.amazon.awssdk.services.s3.model.S3Exception
      IllegalArgumentException
    • putS3Object

      public static String putS3Object(String bucketName, String remoteParent, InputStream is, software.amazon.awssdk.services.s3.S3Client s3Client) throws software.amazon.awssdk.services.s3.model.S3Exception, IllegalArgumentException, IOException
      Upload input stream object to S3. This method load all input stream into buffer. For large file to prevent OOM use putMultipartS3Object method.
      Parameters:
      bucketName - the name of the bucket
      remoteParent - The unique name the object will have in s3, the extension is mandatory, If you wanna upload a file inside a folder/s and keep them also in s3, or you want to create prefix in s3, use: "folder/folder1/file.txt", in amazon you will have: folder/folder1/file.txt.
      is - InputStream to upload
      s3Client - the client you get with ClientManager.getS3Login();
      Returns:
      s3 key where object is been uploaded
      Throws:
      software.amazon.awssdk.services.s3.model.S3Exception
      IllegalArgumentException
      IOException
    • downloadFileObject

      public static String downloadFileObject(String bucketName, String objectKey, software.amazon.awssdk.services.s3.S3Client s3Client, String path) throws software.amazon.awssdk.services.s3.model.S3Exception, IOException
      Method that download a object from s3.
      Parameters:
      bucketName - the name of the bucket
      objectKey - The path in s3 for that object. ex. "folder/folder1/file.txt"
      s3Client - the client you get with ClientManager.getS3Login();
      path - the path where you want to save the file downloaded, must not be a folder, if folder use folder.gz, zip,..
      Returns:
      the Path where the file has been downloaded
      Throws:
      software.amazon.awssdk.services.s3.model.S3Exception
      IOException
    • downloadInputStreamObject

      public static InputStream downloadInputStreamObject(String bucketName, String objectKey, software.amazon.awssdk.services.s3.S3Client s3Client) throws software.amazon.awssdk.services.s3.model.S3Exception
      Throws:
      software.amazon.awssdk.services.s3.model.S3Exception
    • downloadByteArrayObject

      public static byte[] downloadByteArrayObject(String bucketName, String objectKey, software.amazon.awssdk.services.s3.S3Client s3Client) throws software.amazon.awssdk.services.s3.model.S3Exception
      Throws:
      software.amazon.awssdk.services.s3.model.S3Exception
    • generatePresignedUrl

      public static URL generatePresignedUrl(software.amazon.awssdk.services.s3.presigner.S3Presigner presigner, String bucket, String key, int expirationTime)