Interface Storage

All Known Implementing Classes:
PosixStorage, S3Storage

public interface Storage
A high-level interface for performing common operations on a storage system, abstracting away the underlying implementation details. It provides methods for retrieving information on the storage, managing buckets, and working with files and directories, as well as utility methods to add a file system prefix to a path and a list of paths. Implementations of this interface should provide the necessary logic to interact with specific storage systems, such as POSIX or S3.
Author:
Denys Chaykovskiy
  • Method Details

    • getStorageType

      StorageType getStorageType()
      Gets the storage type, e.g. POSIX or S3.
      Returns:
      the storage type
    • getBasePath

      String getBasePath()
      Gets the base path, which is the root directory of the storage system.
      Returns:
      the base path
    • getAbsoluteBasePath

      String getAbsoluteBasePath()
      Gets the absolute base path (file system prefix + bucket + base path), depending on the file system.
      Returns:
      the absolute base path
    • getSourcePath

      String getSourcePath()
      Gets the source path.
      Returns:
      the source path
    • setBucket

      void setBucket(String bucket) throws IOException
      Sets the bucket.
      Parameters:
      bucket - the bucket to set
      Throws:
      IOException - if an error occurs while setting the bucket
    • getBucket

      String getBucket()
      Gets the current bucket.
      Returns:
      the current bucket
    • getBuckets

      List<String> getBuckets() throws IOException
      Gets the buckets from the storage.
      Returns:
      the list of buckets
      Throws:
      IOException - if an error occurs while getting the buckets
    • bucketExists

      boolean bucketExists(String bucketName) throws IOException
      Checks if the bucket exists.
      Parameters:
      bucketName - the name of the bucket
      Returns:
      true if the bucket exists
      Throws:
      IOException - if an error occurs while checking the bucket existence
    • deleteBucket

      void deleteBucket(String bucket) throws IOException
      Deletes a bucket in the storage.
      Parameters:
      bucket - the bucket to delete
      Throws:
      IOException - if an error occurs while deleting the bucket
    • getRelativeFiles

      List<String> getRelativeFiles(String prefix) throws IOException
      Gets files (relative paths) from the storage with the given prefix (folder).
      Parameters:
      prefix - the prefix (folder) to search in the storage
      Returns:
      the list of files starting with the given prefix
      Throws:
      IOException - if an error occurs while getting the relative files
    • getRelativeFiles

      List<String> getRelativeFiles() throws IOException
      Gets all files (relative paths) from the storage.
      Returns:
      the list of all files from the storage
      Throws:
      IOException - if an error occurs while getting the relative files
    • getAbsoluteFiles

      List<String> getAbsoluteFiles(String prefix) throws IOException
      Gets the files (absolute paths) from the storage with the given prefix (folder).
      Parameters:
      prefix - the prefix (folder) to search in the storage
      Returns:
      the list of files starting with the given prefix
      Throws:
      IOException - if an error occurs while getting the absolute files
    • getAbsoluteFiles

      List<String> getAbsoluteFiles() throws IOException
      Gets all files (absolute paths) from the storage.
      Returns:
      the list of all files from the storage
      Throws:
      IOException - if an error occurs while getting the absolute files
    • getRelativePath

      String getRelativePath(String absolutePath)
      Gets the relative path from the absolute path.
      Parameters:
      absolutePath - the absolute path
      Returns:
      the relative path
    • getRelativePath

      List<String> getRelativePath(List<String> absolutePaths)
      Gets the relative paths from the absolute paths.
      Parameters:
      absolutePaths - the absolute paths
      Returns:
      the relative paths
    • getAbsolutePath

      String getAbsolutePath(String relativePath)
      Gets the absolute path depending on the storage file system.
      Parameters:
      relativePath - the relative path
      Returns:
      the absolute file depending on the storage file system
    • getAbsolutePath

      List<String> getAbsolutePath(List<String> relativePaths)
      Gets the absolute paths depending on the storage file system.
      Parameters:
      relativePaths - the relative paths
      Returns:
      the absolute paths depending on the storage file system
    • getStorageFile

      StorageFile getStorageFile(String relativePath)
      Gets the storage file.
      Parameters:
      relativePath - the relative path in the storage to the file
      Returns:
      the storage file object
    • getStorageFiles

      List<StorageFile> getStorageFiles() throws IOException
      Gets the storage files.
      Returns:
      the list of storage files
      Throws:
      IOException - if an error occurs while getting the storage files
    • createStorageFile

      StorageFile createStorageFile(String relativePath, String content) throws IOException
      Physically creates a storage file.
      Parameters:
      relativePath - the relative path of the file
      content - the content of the file
      Returns:
      the storage file object of the created file
      Throws:
      IOException - if an error occurs while creating the storage file
    • fileExists

      boolean fileExists(StorageFile storageFile) throws IOException
      Checks if a file exists.
      Parameters:
      storageFile - the storage file to check
      Returns:
      true if the file exists physically
      Throws:
      IOException - if an error occurs while checking the file existence
    • isFile

      boolean isFile(StorageFile storageFileOrDir) throws IOException
      Checks if a storage file or directory is a file (i.e., no slash at the end of the path).
      Parameters:
      storageFileOrDir - the storage file or directory
      Returns:
      true if the storage file is a file
      Throws:
      IOException - if an error occurs while checking if the storage file is a file
    • isDirectory

      boolean isDirectory(StorageFile storageFileOrDir) throws IOException
      Checks if the storage file or directory is a directory.
      Parameters:
      storageFileOrDir - the storage file or directory
      Returns:
      true if the storage file is a directory
      Throws:
      IOException - if an error occurs while checking if the storage file is a directory
    • getFileSize

      long getFileSize(StorageFile storageFile) throws IOException
      Gets the file size.
      Parameters:
      storageFile - the storage file
      Returns:
      the file size of the storage file
      Throws:
      IOException - if an error occurs while getting the file size
    • getFileContent

      String getFileContent(StorageFile storageFile) throws IOException
      Gets the content of the specified storage file.
      Parameters:
      storageFile - the storage file from which to retrieve the content
      Returns:
      the file content
      Throws:
      IOException - if an error occurs while getting the file content
    • uploadFile

      String uploadFile(StorageFile sourceFile, StorageFile targetFileOrDir) throws IOException
      Uploads a file to the storage.
      Parameters:
      sourceFile - the source file to upload
      targetFileOrDir - the target file or directory in the storage
      Returns:
      the path of the uploaded file
      Throws:
      IOException - if an error occurs while uploading the file
    • upload

      List<String> upload(StorageFile sourceFileOrDir, StorageFile targetFileOrDir) throws IOException
      Uploads a file or directory recursively to the storage.
      Parameters:
      sourceFileOrDir - the source file or directory
      targetFileOrDir - the target file or directory in the storage
      Returns:
      the list of uploaded files
      Throws:
      IOException - if an error occurs while uploading the file or directory
    • upload

      List<String> upload(StorageFile sourceFileOrDir) throws IOException
      Uploads a file or directory recursively to the storage.
      Parameters:
      sourceFileOrDir - the source file or directory to upload
      Returns:
      the list of uploaded files
      Throws:
      IOException - if an error occurs while uploading the file or directory
    • uploadFile

      String uploadFile(StorageFile sourceFile) throws IOException
      Uploads a file to the storage.
      Parameters:
      sourceFile - the source file to upload
      Returns:
      the path of the uploaded file
      Throws:
      IOException - if an error occurs while uploading the file
    • uploadSourceFileOrDir

      List<String> uploadSourceFileOrDir(String relativeSourceFileOrDir) throws IOException
      Uploads a source file or directory recursively to the storage.
      Parameters:
      relativeSourceFileOrDir - the relative path to the source file or directory
      Returns:
      the list of uploaded source files to the storage
      Throws:
      IOException - if an error occurs while uploading the file
    • uploadSourceFile

      String uploadSourceFile(String relativeSourceFile) throws IOException
      Uploads a source file to the storage.
      Parameters:
      relativeSourceFile - the relative path to the source file
      Returns:
      the uploaded source file in the storage
      Throws:
      IOException - if an error occurs while uploading the file
    • download

      List<String> download(StorageFile sourceFileOrDir, StorageFile targetFileOrDir) throws IOException
      Downloads a file or directory recursively from the storage.
      Parameters:
      sourceFileOrDir - the source file or directory in the storage
      targetFileOrDir - the target file or directory
      Returns:
      the list of downloaded files
      Throws:
      IOException - if an error occurs while downloading the file or directory
    • downloadFile

      String downloadFile(StorageFile sourceFile, StorageFile targetFileOrDir) throws IOException
      Downloads a file from the storage.
      Parameters:
      sourceFile - the source file in the storage to download
      targetFileOrDir - the target file or directory
      Returns:
      the downloaded storage file
      Throws:
      IOException - if an error occurs while downloading the file
    • delete

      List<String> delete(StorageFile storageFileOrDir) throws IOException
      Deletes a file or directory recursively from the storage.
      Parameters:
      storageFileOrDir - the storage file or directory to delete
      Returns:
      the list of deleted files from the storage
      Throws:
      IOException - if an error occurs while deleting the file or directory
    • deleteFile

      String deleteFile(StorageFile storageFileOrDir) throws IOException
      Deletes a storage file from the storage.
      Parameters:
      storageFileOrDir - the storage file to delete
      Returns:
      the deleted storage file
      Throws:
      IOException - if an error occurs while deleting the file
    • delete

      List<String> delete(String relativeFileOrDir) throws IOException
      Deletes a file or directory recursively from the storage.
      Parameters:
      relativeFileOrDir - the relative path to the storage file or directory to delete
      Returns:
      the list of deleted files from the storage
      Throws:
      IOException - if an error occurs while deleting the file or directory
    • addFSPrefix

      String addFSPrefix(String path)
      Adds a file system prefix to the path.
      Parameters:
      path - the path to extend
      Returns:
      the file system prefix + path
    • addFSPrefix

      List<String> addFSPrefix(List<String> paths)
      Adds a file system prefix and bucket to paths.
      Parameters:
      paths - the paths to extend
      Returns:
      the list of file system prefix + path
    • getInputStream

      InputStream getInputStream(StorageFile storageFile) throws IOException
      Gets the input stream from a file.
      Parameters:
      storageFile - the storage file
      Returns:
      the input stream from the file
      Throws:
      IOException - if an error occurs while getting the input stream