Package de.dlr.proseo.storagemgr.s3
Class S3Storage
java.lang.Object
de.dlr.proseo.storagemgr.s3.S3Storage
- All Implemented Interfaces:
Storage
An implementation of the Storage interface for a S3-based file system,
providing functionality to interact with the storage system, that is
retrieving information about the storage, performing file operations, and
path conversion.
- Author:
- Denys Chaykovskiy
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddFSPrefix(String path) Adds the file system prefix to the path.addFSPrefix(List<String> paths) Adds the file system prefix to paths.booleanbucketExists(String bucketName) Checks if the bucket exists.createStorageFile(String relativePath, String content) Creates the physical storage file.delete(StorageFile storageFileOrDir) Deletes the file or directory recursively from the storage.Deletes the file or directory recursively from the storage.voiddeleteBucket(String bucketName) Deletes the bucket in storage.deleteFile(StorageFile storageFile) Deletes the storage file from storage.download(StorageFile sourceFileOrDir, StorageFile targetFileOrDir) Downloads the file or directory recursively.downloadFile(StorageFile sourceFile, StorageFile targetFileOrDir) Downloads the file from storage.booleanfileExists(StorageFile storageFile) Checks if the file exists.Gets the absolute base path (fs prefix + bucket + base path), depends on fs.Gets all files (absolute paths) from storage.getAbsoluteFiles(String relativePath) Gets files (absolute paths) from storage with the given relative path.getAbsolutePath(String relativePath) Gets the absolute path (s3://<bucket>/<relativePath>).getAbsolutePath(List<String> relativePaths) Gets the absolute paths (s3://<bucket>/<relativePath>).Gets the base path.Gets the bucket.Gets the buckets from storage.getFileContent(StorageFile storageFile) Gets the file content.longgetFileSize(StorageFile storageFile) Gets the file size.getInputStream(StorageFile storageFile) Gets the input stream from the file.Gets all files from storage.getRelativeFiles(String folder) Gets the files from storage with the given prefix (folder).getRelativePath(String absolutePath) Gets the relative path from the absolute path by removing the S3 prefix, bucket, and left slash.getRelativePath(List<String> absolutePaths) Gets the relative paths from the absolute paths by removing the S3 prefix, bucket, and left slash.Gets the source path.getStorageFile(String relativePath) Gets the Storage File.Gets the storage files.Gets the storage type.booleanisDirectory(StorageFile storageFileOrDir) Checks if the storage file or directory is a directory.booleanisFile(StorageFile storageFileOrDir) Checks if the storage file or directory is a file (no slash at the end of the path).voidSets the bucket.upload(StorageFile sourceFileOrDir) Uploads the file or directory recursively to the storage.upload(StorageFile sourceFileOrDir, StorageFile targetFileOrDir) Uploads the file or directory recursively to storage.uploadFile(StorageFile sourceFile) Uploads the file to the storage.uploadFile(StorageFile sourceFile, StorageFile targetFileOrDir) Uploads the file to storage.uploadSourceFile(String relativeSourceFile) Uploads the source file.uploadSourceFileOrDir(String relativeSourceFileOrDir) Uploads the source file or directory recursively to the storage.
-
Constructor Details
-
S3Storage
Constructor with the s3 configuration- Parameters:
cfg- s3 configuration- Throws:
IOException- if an I/O exception occurs
-
-
Method Details
-
getStorageType
Gets the storage type.- Specified by:
getStorageTypein interfaceStorage- Returns:
- the storage type
-
getBasePath
Gets the base path.- Specified by:
getBasePathin interfaceStorage- Returns:
- the base path
-
getAbsoluteBasePath
Gets the absolute base path (fs prefix + bucket + base path), depends on fs. In other words, it is the absolute path without the relative path in this S3 version. s3://bucket/- Specified by:
getAbsoluteBasePathin interfaceStorage- Returns:
- the absolute base path
-
getSourcePath
Gets the source path.- Specified by:
getSourcePathin interfaceStorage- Returns:
- the source path
-
setBucket
Sets the bucket.- Specified by:
setBucketin interfaceStorage- Parameters:
bucket- the bucket to set- Throws:
IOException- if an I/O exception occurs
-
getBucket
Gets the bucket. -
getBuckets
Gets the buckets from storage.- Specified by:
getBucketsin interfaceStorage- Returns:
- the list of buckets
- Throws:
IOException- if an I/O exception occurs
-
bucketExists
Checks if the bucket exists.- Specified by:
bucketExistsin interfaceStorage- Parameters:
bucketName- the name of the bucket- Returns:
- true if the bucket exists
- Throws:
IOException- if an I/O exception occurs
-
deleteBucket
Deletes the bucket in storage.- Specified by:
deleteBucketin interfaceStorage- Parameters:
bucketName- the bucket to delete- Throws:
IOException- if the bucket cannot be deleted
-
getRelativeFiles
Gets the files from storage with the given prefix (folder).- Specified by:
getRelativeFilesin interfaceStorage- Parameters:
folder- the prefix (folder) for search in storage- Returns:
- the list of files with the given prefix
- Throws:
IOException- if an I/O exception occurs
-
getRelativeFiles
Gets all files from storage.- Specified by:
getRelativeFilesin interfaceStorage- Returns:
- the list of all files from storage
- Throws:
IOException- if an I/O exception occurs
-
getAbsoluteFiles
Gets files (absolute paths) from storage with the given relative path.- Specified by:
getAbsoluteFilesin interfaceStorage- Parameters:
relativePath- the relative path for search in storage- Returns:
- the list of files with the given prefix
- Throws:
IOException- if an I/O exception occurs
-
getAbsoluteFiles
Gets all files (absolute paths) from storage.- Specified by:
getAbsoluteFilesin interfaceStorage- Returns:
- the list of all files from storage
- Throws:
IOException- if an I/O exception occurs
-
getRelativePath
Gets the relative path from the absolute path by removing the S3 prefix, bucket, and left slash.- Specified by:
getRelativePathin interfaceStorage- Parameters:
absolutePath- the absolute path- Returns:
- the relative path
-
getRelativePath
Gets the relative paths from the absolute paths by removing the S3 prefix, bucket, and left slash.- Specified by:
getRelativePathin interfaceStorage- Parameters:
absolutePaths- the absolute paths- Returns:
- the relative paths
-
getAbsolutePath
Gets the absolute path (s3://<bucket>/<relativePath>).- Specified by:
getAbsolutePathin interfaceStorage- Parameters:
relativePath- the relative path- Returns:
- the absolute file depending on the storage file system
-
getAbsolutePath
Gets the absolute paths (s3://<bucket>/<relativePath>).- Specified by:
getAbsolutePathin interfaceStorage- Parameters:
relativePaths- the relative paths- Returns:
- the absolute paths depending on the storage file system
-
getStorageFile
Gets the Storage File.- Specified by:
getStorageFilein interfaceStorage- Parameters:
relativePath- the relative path in storage to the file- Returns:
- the storage file object
-
getStorageFiles
Gets the storage files.- Specified by:
getStorageFilesin interfaceStorage- Returns:
- the list of storage files
- Throws:
IOException- if an I/O exception occurs
-
createStorageFile
Creates the physical storage file.- Specified by:
createStorageFilein interfaceStorage- Parameters:
relativePath- the relative path of the filecontent- the content of the file- Returns:
- the storage file object of the created file
- Throws:
IOException- if the file cannot be created
-
fileExists
Checks if the file exists.- Specified by:
fileExistsin interfaceStorage- Parameters:
storageFile- the storage file to check- Returns:
- true if the file exists physically
- Throws:
IOException- if an I/O exception occurs
-
isFile
Checks if the storage file or directory is a file (no slash at the end of the path).- Specified by:
isFilein interfaceStorage- Parameters:
storageFileOrDir- the storage file or directory- Returns:
- true if the storage file is a file
- Throws:
IOException- if an I/O exception occurs
-
isDirectory
Checks if the storage file or directory is a directory.- Specified by:
isDirectoryin interfaceStorage- Parameters:
storageFileOrDir- the storage file or directory- Returns:
- true if the storage file is a file
- Throws:
IOException- if an I/O exception occurs
-
getFileSize
Gets the file size.- Specified by:
getFileSizein interfaceStorage- Parameters:
storageFile- the storage file- Returns:
- the file size of the storage file
- Throws:
IOException- if an I/O exception occurs
-
getFileContent
Gets the file content.- Specified by:
getFileContentin interfaceStorage- Parameters:
storageFile- the storage file- Returns:
- the file content
- Throws:
IOException- if an error occurs while getting the file content
-
uploadFile
Uploads the file to storage.- Specified by:
uploadFilein interfaceStorage- Parameters:
sourceFile- the source file to uploadtargetFileOrDir- the target file or directory in the storage- Returns:
- the uploaded storage file
- Throws:
IOException- if the file cannot be uploaded
-
upload
public List<String> upload(StorageFile sourceFileOrDir, StorageFile targetFileOrDir) throws IOException Uploads the file or directory recursively to storage.- Specified by:
uploadin interfaceStorage- Parameters:
sourceFileOrDir- the source file or directorytargetFileOrDir- the target file or directory in the storage- Returns:
- the list of uploaded files
- Throws:
IOException- if the file or directory cannot be uploaded
-
upload
Uploads the file or directory recursively to the storage.- Specified by:
uploadin interfaceStorage- Parameters:
sourceFileOrDir- the source file or dir to upload- Returns:
- the list of uploaded files
- Throws:
IOException- if the file or directory cannot be uploaded
-
uploadFile
Uploads the file to the storage.- Specified by:
uploadFilein interfaceStorage- Parameters:
sourceFile- the source file to upload- Returns:
- the path of the uploaded file
- Throws:
IOException- if the file cannot be uploaded
-
uploadSourceFileOrDir
Uploads the source file or directory recursively to the storage.- Specified by:
uploadSourceFileOrDirin interfaceStorage- Parameters:
relativeSourceFileOrDir- the relative path to source file or directory- Returns:
- the list of uploaded to storage source files
- Throws:
IOException- if the file cannot be uploaded
-
uploadSourceFile
Uploads the source file.- Specified by:
uploadSourceFilein interfaceStorage- Parameters:
relativeSourceFile- the relative path to source file- Returns:
- the uploaded to storage source file
- Throws:
IOException- if the file cannot be uploaded
-
download
public List<String> download(StorageFile sourceFileOrDir, StorageFile targetFileOrDir) throws IOException Downloads the file or directory recursively.- Specified by:
downloadin interfaceStorage- Parameters:
sourceFileOrDir- the source file or directory in the storagetargetFileOrDir- the target file or directory- Returns:
- the list of downloaded files
- Throws:
IOException- if the file cannot be downloaded
-
downloadFile
Downloads the file from storage.- Specified by:
downloadFilein interfaceStorage- Parameters:
sourceFile- the storage source file to downloadtargetFileOrDir- the target file or directory- Returns:
- the Storage File object with the downloaded file
- Throws:
IOException- if the file cannot be downloaded
-
delete
Deletes the file or directory recursively from the storage.- Specified by:
deletein interfaceStorage- Parameters:
storageFileOrDir- the Storage file or directory to delete- Returns:
- the list of deleted files from storage
- Throws:
IOException- if the file or directory cannot be deleted
-
deleteFile
Deletes the storage file from storage.- Specified by:
deleteFilein interfaceStorage- Parameters:
storageFile- the storage file to delete- Returns:
- the deleted storage file
- Throws:
IOException- if the file cannot be deleted
-
delete
Deletes the file or directory recursively from the storage.- Specified by:
deletein interfaceStorage- Parameters:
relativeFileOrDir- the Storage file or directory to delete- Returns:
- the list of deleted files from storage
- Throws:
IOException- if the file or directory cannot be deleted
-
addFSPrefix
Adds the file system prefix to the path.- Specified by:
addFSPrefixin interfaceStorage- Parameters:
path- the path to extend- Returns:
- the file system prefix + "|" + path
-
addFSPrefix
Adds the file system prefix to paths.- Specified by:
addFSPrefixin interfaceStorage- Parameters:
paths- the paths to extend- Returns:
- the list of file system prefix + path
-
getInputStream
Gets the input stream from the file.- Specified by:
getInputStreamin interfaceStorage- Parameters:
storageFile- the storage file- Returns:
- the input stream from the file
- Throws:
IOException- if an error occurs while getting the input stream
-