Package de.dlr.proseo.storagemgr.s3
Klasse S3DAL
java.lang.Object
de.dlr.proseo.storagemgr.s3.S3DAL
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
-
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungboolean
bucketExists
(String bucketName) Checks if a bucket exists in the storage system.Deletes a file or directory from the default bucket.Deletes a file or directory from the named bucket.void
deleteBucket
(String bucketName) Deletes a bucket from the storage system.deleteFile
(String filepath) Deletes a file from the default bucket.deleteFile
(String bucket, String filepath) Deletes a file from the named bucket.Deletes files in the default bucket.deleteFiles
(String bucket) Deletes files in the named bucket.deleteFiles
(String bucket, List<String> toDeleteList) Deletes named files from the given bucket.deleteFiles
(List<String> toDeleteList) Deletes named files from the default bucket.Downloads a file or directory from the default bucket of the storage system.Downloads a file or directory from the named bucket in the storage system.downloadByPrefix
(String prefixFileOrDir) Downloads a file or directory with a prefix match from the default bucket of the storage system.downloadByPrefix
(String bucket, String prefixFileOrDir) Downloads a file or directory with a prefix match from the named bucket in the storage system.downloadFile
(String sourceFile, String targetFileOrDir) Downloads a file from the default bucket of the storage system.downloadFile
(String bucket, String sourceFile, String targetFileOrDir) Downloads a file from the named bucket in the storage system.boolean
fileExists
(String filePath) Checks if a file exists in the default bucket.boolean
fileExists
(String bucket, String filePath) Checks if a file exists in the named S3 bucket.Retrieves a list of all files in the default bucket.getAllFiles
(String bucket) Retrieves a list of all files in the named bucket.Gets the list of available buckets.Gets the S3 configuration used by this S3DAL instance.Gets the currently default bucket.getFileContent
(String filePath) Retrieves the content of the file in the default bucket specified by the file path.getFileContent
(String bucket, String filePath) Retrieves the content of the file in the named bucket specified by the file path.getFileName
(String path) Gets the name of the file from the specified path.Retrieves a list of files from the default bucket that match the specified folder (prefix).Retrieves a list of files from the given bucket that match the specified folder (prefix).long
getFileSize
(String filePath) Retrieves the size of the file in the default bucket specified by the file path.long
getFileSize
(String bucket, String filePath) Retrieves the size of the file in the named bucket specified by the file path.getInputStream
(String relativePath) Gets an input stream from a file in the default bucket of the storage system.getInputStream
(String bucket, String relativePath) Gets an input stream from a file in the named bucket of the storage system.void
Initializes the S3 v1 client.void
Initializes the S3 v2 client.boolean
Checks if the specified path represents a file (not a directory).void
setDefaultBucket
(String bucket) Sets the default bucket to use for operations.uploadFile
(String sourceFile, String targetFileOrDir) Uploads a file to the default bucket in the storage system.uploadFile
(String sourceFile, String bucket, String targetFileOrDir) Uploads a file to the named bucket in the storage system.uploadFileOrDir
(String sourceFileOrDir, String targetFileOrDir) Uploads a file or directory to the default bucket in the storage system.uploadFileOrDir
(String sourceFileOrDir, String bucket, String targetFileOrDir) Uploads a file or directory to the named bucket in the storage system.
-
Konstruktordetails
-
S3DAL
Constructor- Parameter:
cfg
- s3Configuration- Löst aus:
IOException
- if an I/O exception occurs
-
-
Methodendetails
-
getConfiguration
Gets the S3 configuration used by this S3DAL instance.- Gibt zurück:
- the S3Configuration object
-
initS3ClientV1
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
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
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
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
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
Retrieves a list of files from the given bucket that match the specified folder (prefix).- Parameter:
bucket
- the bucket to search infolder
- 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
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
Checks if a file exists in the named S3 bucket.- Parameter:
bucket
- the bucket to checkfilePath
- the file path- Gibt zurück:
- true if the file exists, false otherwise
- Löst aus:
IOException
- if an I/O exception occurs
-
isFile
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
Gets the name of the file from the specified path.- Parameter:
path
- the file path- Gibt zurück:
- the name of the file
-
getFileSize
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
Retrieves the size of the file in the named bucket specified by the file path.- Parameter:
bucket
- the bucket to checkfilePath
- the file path- Gibt zurück:
- the size of the file in bytes
- Löst aus:
IOException
- if an I/O exception occurs
-
getFileContent
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
Retrieves the content of the file in the named bucket specified by the file path.- Parameter:
bucket
- the bucket to retrieve the file fromfilePath
- the file path- Gibt zurück:
- the content of the file
- Löst aus:
IOException
- if an I/O exception occurs
-
uploadFile
Uploads a file to the default bucket in the storage system.- Parameter:
sourceFile
- the source file to uploadtargetFileOrDir
- 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 uploadbucket
- the bucket to upload totargetFileOrDir
- 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 uploadtargetFileOrDir
- 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 uploadbucket
- the bucket to upload totargetFileOrDir
- 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
Downloads a file from the default bucket of the storage system.- Parameter:
sourceFile
- the source file in the storage system to downloadtargetFileOrDir
- 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 fromsourceFile
- the source file in the storage system to downloadtargetFileOrDir
- 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
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 downloadtargetFileOrDir
- 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 fromsourceFileOrDir
- the source file or directory in the storage system to downloadtargetFileOrDir
- 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
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
Downloads a file or directory with a prefix match from the named bucket in the storage system.- Parameter:
bucket
- the bucket to download fromprefixFileOrDir
- 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
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
Deletes a file or directory from the named bucket.- Parameter:
bucket
- the bucket to delete the file or directory fromfileOrDir
- 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
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
Deletes a file from the named bucket.- Parameter:
bucket
- the bucket to delete the file fromfilepath
- the file path- Gibt zurück:
- the deleted file path
- Löst aus:
IOException
- if an I/O exception occurs
-
deleteFiles
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
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
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
Deletes named files from the given bucket.- Parameter:
bucket
- the bucket to delete files fromtoDeleteList
- a list of file or directory paths to delete- Gibt zurück:
- a list of deleted file paths
-
setDefaultBucket
Sets the default bucket to use for operations.- Parameter:
bucket
- the bucket name- Löst aus:
IOException
- if an I/O exception occurs
-
getDefaultBucket
Gets the currently default bucket.- Gibt zurück:
- the default bucket name
-
getBuckets
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
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
Deletes a bucket from the storage system.- Parameter:
bucketName
- the bucket name- Löst aus:
IOException
- if an I/O exception occurs
-
getInputStream
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
Gets an input stream from a file in the named bucket of the storage system.- Parameter:
bucket
- the bucket to retrieve the file fromrelativePath
- 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
-