Klasse StorageProvider

java.lang.Object
de.dlr.proseo.storagemgr.StorageProvider

@Component public class StorageProvider extends Object
A central manager for different types of storage in the application. It handles the creation, retrieval, and management of storage instances, provides file-related operations and paths, and offers various utility methods related to storage management. This class acts as a singleton and manages the storage configuration, source paths, and storage operations. Author: Denys Chaykovskiy
  • Felddetails

    • basePaths

      List<String> basePaths
      Base Paths are used to get relative path from absolute path
  • Konstruktordetails

    • StorageProvider

      public StorageProvider()
      Simple default constructor
  • Methodendetails

    • getInstance

      public static StorageProvider getInstance()
      Returns the instance of the storage provider (singleton).
      Gibt zurück:
      the storage provider singleton instance
    • loadDefaultPaths

      public void loadDefaultPaths()
      Load default source, storage, and cache paths
    • setSourcePath

      public void setSourcePath(String sourcePath)
      Sets the source path.
      Parameter:
      sourcePath - the source path to set
    • setCachePath

      public void setCachePath(String cachePath)
      Sets the cache path.
      Parameter:
      cachePath - the cache path to set
    • getSourcePath

      public String getSourcePath()
      Gets the source path.
      Gibt zurück:
      the source path
    • getDefaultStoragePath

      public String getDefaultStoragePath()
      Gets the default POSIX storage path.
      Gibt zurück:
      the POSIX storage path
    • getCachePath

      public String getCachePath()
      Gets the cache path.
      Gibt zurück:
      the cache path
    • getStorage

      public Storage getStorage()
      Gets the current storage instance.
      Gibt zurück:
      the current defaultStorage instance
    • getDefaultStorage

      public Storage getDefaultStorage(StorageType storageType) throws IOException
      Gets the default storage instance based on the specified storage type.
      Parameter:
      storageType - the storage type
      Gibt zurück:
      the storage instance
      Löst aus:
      IOException - if an error occurs during storage creation
    • getStorage

      public Storage getStorage(StorageType storageType, String storagePath) throws IOException
      Gets the desired storage instance based on the specified storage type.
      Parameter:
      storageType - the storage type
      storagePath - the base path for a POSIX storage and the bucket for an S3 storage
      Gibt zurück:
      the storage instance
      Löst aus:
      IOException - if an error occurs during storage creation
    • getStorage

      public Storage getStorage(String absolutePath) throws IOException
      Gets the storage instance based on the specified absolute path.
      Parameter:
      absolutePath - the absolute path
      Gibt zurück:
      the storage instance
      Löst aus:
      IOException - if an error occurs during storage retrieval
    • setDefaultStorage

      public Storage setDefaultStorage(StorageType storageType) throws IOException
      Sets the default storage type and creates the corresponding storage instance. NOT INTENDED FOR USE OUTSIDE UNIT TEST CASES!
      Parameter:
      storageType - the storage type to set
      Gibt zurück:
      the created storage instance
      Löst aus:
      IOException - if an error occurs during storage creation
    • getBasePaths

      public List<String> getBasePaths()
      Gets the list of base paths.
      Gibt zurück:
      the list of base paths
    • getCacheFileSize

      public long getCacheFileSize(String relativePath) throws IOException
      Gets the file size of the cache file specified by the relative path.
      Parameter:
      relativePath - the relative path of the cache file
      Gibt zurück:
      the file size in bytes
      Löst aus:
      IOException - if an error occurs while getting the file size
    • getSourceFileSize

      public long getSourceFileSize(String relativePath) throws IOException
      Gets the file size of the source file specified by the relative path.
      Parameter:
      relativePath - the relative path of the source file
      Gibt zurück:
      the file size in bytes
      Löst aus:
      IOException - if an error occurs while getting the file size
    • getPosixFileSize

      public long getPosixFileSize(String absolutePath) throws IOException
      Gets the file size of the posix file specified by the absolute path.
      Parameter:
      absolutePath - the absolute path of the posix file
      Gibt zurück:
      the file size in bytes
      Löst aus:
      IOException - if an error occurs while getting the file size
    • getCacheFile

      public StorageFile getCacheFile(String relativePath)
      Gets the cache file as a StorageFile from the relative path. The path can be virtual.
      Parameter:
      relativePath - the relative path of the cache file
      Gibt zurück:
      the StorageFile representing the cache file
    • getSourceFile

      public StorageFile getSourceFile(String relativePath)
      Gets the source file as a StorageFile from the relative path. The path can be virtual.
      Parameter:
      relativePath - the relative path of the source file
      Gibt zurück:
      the StorageFile representing the source file
    • getPosixFile

      public StorageFile getPosixFile(String basePath, String relativePath)
      Gets the posix file as a StorageFile from the relative path. The path can be virtual.
      Parameter:
      basePath - the base path of the posix defaultStorage
      relativePath - the relative path of the file
      Gibt zurück:
      the StorageFile representing the posix file
    • getStorageFile

      public StorageFile getStorageFile(Storage storage, String relativePath)
      Gets the storage file as a StorageFile from the relative path. The path can be virtual.
      Parameter:
      storage - the storage to get the file from
      relativePath - the relative path of the file
      Gibt zurück:
      the StorageFile representing the storage file
    • getStorageFileFromDefaultStorage

      public StorageFile getStorageFileFromDefaultStorage(String relativePath)
      Gets the storage file as a StorageFile from the relative path. The path can be virtual using the default storage
      Parameter:
      relativePath - the relative path of the file
      Gibt zurück:
      the StorageFile representing the storage file
    • getAbsoluteFile

      public StorageFile getAbsoluteFile(String absolutePath)
      Gets a file as a POSIX StorageFile from the absolute path. The path to the file can be virtual.
      Parameter:
      absolutePath - the absolute path to the file
      Gibt zurück:
      the StorageFile representing the file
    • getAbsoluteSourcePath

      public String getAbsoluteSourcePath(String relativePath)
      Gets the absolute source path from the relative path.
      Parameter:
      relativePath - the relative path to the file
      Gibt zurück:
      the absolute source path from the relative path
    • getAbsoluteCachePath

      public String getAbsoluteCachePath(String relativePath)
      Gets the absolute cache path from the relative path.
      Parameter:
      relativePath - the relative path to the file
      Gibt zurück:
      the absolute cache path from the relative path
    • getRelativePath

      public String getRelativePath(String absolutePath) throws IOException
      Gets the relative path from the absolute path using the base path list.
      Parameter:
      absolutePath - the absolute path
      Gibt zurück:
      the relative path
      Löst aus:
      IOException - if an error occurs while getting the relative path
    • createStorageFile

      public StorageFile createStorageFile(String relativePath, String content) throws IOException
      Creates a physical file in the storage based on the relative path and content.
      Parameter:
      relativePath - the relative path to the file
      content - the content of the file
      Gibt zurück:
      the StorageFile representing the physically created file
      Löst aus:
      IOException - if an error occurs while creating the storage file
    • getPosixConfigurationFromFile

      public PosixConfiguration getPosixConfigurationFromFile()
      Gets the POSIX configuration from the file.
      Gibt zurück:
      the POSIX configuration
    • getS3ConfigurationFromFile

      public S3Configuration getS3ConfigurationFromFile()
      Gets the S3 configuration from the file.
      Gibt zurück:
      the S3 configuration
    • copyAbsoluteFilesToCache

      public List<String> copyAbsoluteFilesToCache(String sourceFile, StorageFile destCacheFile) throws IOException
      Copies files from an absolute source path to an absolute path in the cache
      Parameter:
      sourceFile - the file path to copy from
      destCacheFile - the file path to copy to
      Gibt zurück:
      a path list of copied files
      Löst aus:
      IOException