Klasse S3DAL

java.lang.Object
de.dlr.proseo.storagemgr.s3.S3DAL

public class S3DAL extends Object
A data access layer for interacting with a S3-based storage system. It provides various methods to perform operations such as retrieving files, checking file or directory existence, obtaining file content, uploading files, downloading files, and deleting files or directories within the S3 storage system. This class utilizes the Amazon S3 SDK v2 for S3 client operations and requires AWS credentials and a S3 configuration to be initialized.
Autor:
Denys Chaykovskiy
  • Konstruktordetails

  • Methodendetails

    • getConfiguration

      public S3Configuration getConfiguration()
      Gets the S3 configuration used by this S3DAL instance.
      Gibt zurück:
      the S3Configuration object
    • initS3ClientV1

      public void initS3ClientV1() throws IOException
      Initializes the S3 v1 client. Note that this method relies on the configuration passed to the current object upon construction. It is assumed that this configuration is derived from the application configuration without modification, so it is the same for every S3DAL object.
      Löst aus:
      IOException - if an I/O exception occurs
    • initS3ClientV2

      public void initS3ClientV2() throws IOException
      Initializes the S3 v2 client. Note that this method relies on the configuration passed to the current object upon construction. It is assumed that this configuration is derived from the application configuration without modification, so it is the same for every S3DAL object.
      Löst aus:
      IOException - if an I/O exception occurs
    • getAllFiles

      public List<String> getAllFiles() throws IOException
      Retrieves a list of all files in the default bucket.
      Gibt zurück:
      a list of all file paths
      Löst aus:
      IOException - if an I/O exception occurs
    • getAllFiles

      public List<String> getAllFiles(String bucket) throws IOException
      Retrieves a list of all files in the named bucket.
      Parameter:
      bucket - the bucket to search in
      Gibt zurück:
      a list of all file paths
      Löst aus:
      IOException - if an I/O exception occurs
    • getFiles

      public List<String> getFiles(String folder) throws IOException
      Retrieves a list of files from the default bucket that match the specified folder (prefix).
      Parameter:
      folder - the folder (prefix) to match
      Gibt zurück:
      a list of file paths that match the folder
      Löst aus:
      IOException - if an I/O exception occurs
    • getFiles

      public List<String> getFiles(String bucket, String folder) throws IOException
      Retrieves a list of files from the given bucket that match the specified folder (prefix).
      Parameter:
      bucket - the bucket to search in
      folder - the folder (prefix) to match
      Gibt zurück:
      a list of file paths that match the folder
      Löst aus:
      IOException - if an I/O exception occurs
    • fileExists

      public boolean fileExists(String filePath) throws IOException
      Checks if a file exists in the default bucket.
      Parameter:
      filePath - the file path
      Gibt zurück:
      true if the file exists, false otherwise
      Löst aus:
      IOException - if an I/O exception occurs
    • fileExists

      public boolean fileExists(String bucket, String filePath) throws IOException
      Checks if a file exists in the named S3 bucket.
      Parameter:
      bucket - the bucket to check
      filePath - the file path
      Gibt zurück:
      true if the file exists, false otherwise
      Löst aus:
      IOException - if an I/O exception occurs
    • isFile

      public boolean isFile(String path)
      Checks if the specified path represents a file (not a directory).
      Parameter:
      path - the path to check
      Gibt zurück:
      true if the path represents a file, false otherwise
    • getFileName

      public String getFileName(String path)
      Gets the name of the file from the specified path.
      Parameter:
      path - the file path
      Gibt zurück:
      the name of the file
    • getFileSize

      public long getFileSize(String filePath) throws IOException
      Retrieves the size of the file in the default bucket specified by the file path.
      Parameter:
      filePath - the file path
      Gibt zurück:
      the size of the file in bytes
      Löst aus:
      IOException - if an I/O exception occurs
    • getFileSize

      public long getFileSize(String bucket, String filePath) throws IOException
      Retrieves the size of the file in the named bucket specified by the file path.
      Parameter:
      bucket - the bucket to check
      filePath - the file path
      Gibt zurück:
      the size of the file in bytes
      Löst aus:
      IOException - if an I/O exception occurs
    • getFileContent

      public String getFileContent(String filePath) throws IOException
      Retrieves the content of the file in the default bucket specified by the file path.
      Parameter:
      filePath - the file path
      Gibt zurück:
      the content of the file
      Löst aus:
      IOException - if an I/O exception occurs
    • getFileContent

      public String getFileContent(String bucket, String filePath) throws IOException
      Retrieves the content of the file in the named bucket specified by the file path.
      Parameter:
      bucket - the bucket to retrieve the file from
      filePath - the file path
      Gibt zurück:
      the content of the file
      Löst aus:
      IOException - if an I/O exception occurs
    • uploadFile

      public String uploadFile(String sourceFile, String targetFileOrDir) throws IOException
      Uploads a file to the default bucket in the storage system.
      Parameter:
      sourceFile - the source file to upload
      targetFileOrDir - the target file or directory in the storage system
      Gibt zurück:
      the uploaded file path in the storage system
      Löst aus:
      IOException - if an I/O exception occurs if the file cannot be uploaded
    • uploadFile

      public String uploadFile(String sourceFile, String bucket, String targetFileOrDir) throws IOException
      Uploads a file to the named bucket in the storage system.
      Parameter:
      sourceFile - the source file to upload
      bucket - the bucket to upload to
      targetFileOrDir - the target file or directory in the storage system
      Gibt zurück:
      the uploaded file path in the storage system
      Löst aus:
      IOException - if an I/O exception occurs if the file cannot be uploaded
    • uploadFileOrDir

      public List<String> uploadFileOrDir(String sourceFileOrDir, String targetFileOrDir) throws IOException
      Uploads a file or directory to the default bucket in the storage system.
      Parameter:
      sourceFileOrDir - the source file or directory to upload
      targetFileOrDir - the target file or directory in the storage system
      Gibt zurück:
      a list of uploaded file paths in the storage system
      Löst aus:
      IOException - if an I/O exception occurs if the file or directory cannot be uploaded
    • uploadFileOrDir

      public List<String> uploadFileOrDir(String sourceFileOrDir, String bucket, String targetFileOrDir) throws IOException
      Uploads a file or directory to the named bucket in the storage system.
      Parameter:
      sourceFileOrDir - the source file or directory to upload
      bucket - the bucket to upload to
      targetFileOrDir - the target file or directory in the storage system
      Gibt zurück:
      a list of uploaded file paths in the storage system
      Löst aus:
      IOException - if an I/O exception occurs if the file or directory cannot be uploaded
    • downloadFile

      public String downloadFile(String sourceFile, String targetFileOrDir) throws IOException
      Downloads a file from the default bucket of the storage system.
      Parameter:
      sourceFile - the source file in the storage system to download
      targetFileOrDir - the target file or directory to download to
      Gibt zurück:
      the downloaded file path
      Löst aus:
      IOException - if an I/O exception occurs if the file cannot be downloaded
    • downloadFile

      public String downloadFile(String bucket, String sourceFile, String targetFileOrDir) throws IOException
      Downloads a file from the named bucket in the storage system.
      Parameter:
      bucket - the bucket to download from
      sourceFile - the source file in the storage system to download
      targetFileOrDir - the target file or directory to download to
      Gibt zurück:
      the downloaded file path
      Löst aus:
      IOException - if an I/O exception occurs if the file cannot be downloaded
    • download

      public List<String> download(String sourceFileOrDir, String targetFileOrDir) throws IOException
      Downloads a file or directory from the default bucket of the storage system.
      Parameter:
      sourceFileOrDir - the source file or directory in the storage system to download
      targetFileOrDir - the target file or directory to download to
      Gibt zurück:
      a list of downloaded file or directory paths
      Löst aus:
      IOException - if an I/O exception occurs if the file or directory cannot be downloaded
    • download

      public List<String> download(String bucket, String sourceFileOrDir, String targetFileOrDir) throws IOException
      Downloads a file or directory from the named bucket in the storage system.
      Parameter:
      bucket - the bucket to download from
      sourceFileOrDir - the source file or directory in the storage system to download
      targetFileOrDir - the target file or directory to download to
      Gibt zurück:
      a list of downloaded file or directory paths
      Löst aus:
      IOException - if an I/O exception occurs if the file or directory cannot be downloaded
    • downloadByPrefix

      public List<String> downloadByPrefix(String prefixFileOrDir) throws IOException
      Downloads a file or directory with a prefix match from the default bucket of the storage system.
      Parameter:
      prefixFileOrDir - the prefix file or directory to match
      Gibt zurück:
      a list of downloaded file paths
      Löst aus:
      IOException - if an I/O exception occurs if the file or directory cannot be downloaded
    • downloadByPrefix

      public List<String> downloadByPrefix(String bucket, String prefixFileOrDir) throws IOException
      Downloads a file or directory with a prefix match from the named bucket in the storage system.
      Parameter:
      bucket - the bucket to download from
      prefixFileOrDir - the prefix file or directory to match
      Gibt zurück:
      a list of downloaded file paths
      Löst aus:
      IOException - if an I/O exception occurs if the file or directory cannot be downloaded
    • delete

      public List<String> delete(String fileOrDir) throws IOException
      Deletes a file or directory from the default bucket.
      Parameter:
      fileOrDir - the file or directory to delete
      Gibt zurück:
      a list of deleted file paths
      Löst aus:
      IOException - if an I/O exception occurs
    • delete

      public List<String> delete(String bucket, String fileOrDir) throws IOException
      Deletes a file or directory from the named bucket.
      Parameter:
      bucket - the bucket to delete the file or directory from
      fileOrDir - the file or directory to delete
      Gibt zurück:
      a list of deleted file paths
      Löst aus:
      IOException - if an I/O exception occurs
    • deleteFile

      public String deleteFile(String filepath) throws IOException
      Deletes a file from the default bucket.
      Parameter:
      filepath - the file path
      Gibt zurück:
      the deleted file path
      Löst aus:
      IOException - if an I/O exception occurs
    • deleteFile

      public String deleteFile(String bucket, String filepath) throws IOException
      Deletes a file from the named bucket.
      Parameter:
      bucket - the bucket to delete the file from
      filepath - the file path
      Gibt zurück:
      the deleted file path
      Löst aus:
      IOException - if an I/O exception occurs
    • deleteFiles

      public List<String> deleteFiles() throws IOException
      Deletes files in the default bucket.
      Gibt zurück:
      a list of deleted file paths
      Löst aus:
      IOException - if an I/O exception occurs
    • deleteFiles

      public List<String> deleteFiles(String bucket) throws IOException
      Deletes files in the named bucket.
      Parameter:
      bucket - the bucket to delete files from
      Gibt zurück:
      a list of deleted file paths
      Löst aus:
      IOException - if an I/O exception occurs
    • deleteFiles

      public List<String> deleteFiles(List<String> toDeleteList)
      Deletes named files from the default bucket.
      Parameter:
      toDeleteList - a list of file or directory paths to delete
      Gibt zurück:
      a list of deleted file paths
    • deleteFiles

      public List<String> deleteFiles(String bucket, List<String> toDeleteList)
      Deletes named files from the given bucket.
      Parameter:
      bucket - the bucket to delete files from
      toDeleteList - a list of file or directory paths to delete
      Gibt zurück:
      a list of deleted file paths
    • setDefaultBucket

      public void setDefaultBucket(String bucket) throws IOException
      Sets the default bucket to use for operations.
      Parameter:
      bucket - the bucket name
      Löst aus:
      IOException - if an I/O exception occurs
    • getDefaultBucket

      public String getDefaultBucket()
      Gets the currently default bucket.
      Gibt zurück:
      the default bucket name
    • getBuckets

      public List<String> getBuckets() throws IOException
      Gets the list of available buckets.
      Gibt zurück:
      a list of bucket names
      Löst aus:
      IOException - if an I/O exception occurs
    • bucketExists

      public boolean bucketExists(String bucketName) throws IOException
      Checks if a bucket exists in the storage system.
      Parameter:
      bucketName - the bucket name
      Gibt zurück:
      true if the bucket exists, false otherwise
      Löst aus:
      IOException - if an I/O exception occurs
    • deleteBucket

      public void deleteBucket(String bucketName) throws IOException
      Deletes a bucket from the storage system.
      Parameter:
      bucketName - the bucket name
      Löst aus:
      IOException - if an I/O exception occurs
    • getInputStream

      public InputStream getInputStream(String relativePath) throws IOException
      Gets an input stream from a file in the default bucket of the storage system.
      Parameter:
      relativePath - the relative file path
      Gibt zurück:
      an InputStream object for reading the file content
      Löst aus:
      IOException - if an I/O exception occurs
    • getInputStream

      public InputStream getInputStream(String bucket, String relativePath) throws IOException
      Gets an input stream from a file in the named bucket of the storage system.
      Parameter:
      bucket - the bucket to retrieve the file from
      relativePath - the relative file path
      Gibt zurück:
      an InputStream object for reading the file content
      Löst aus:
      IOException - if an I/O exception occurs