Class LocalFileStorage

java.lang.Object
io.jmix.localfs.LocalFileStorage
All Implemented Interfaces:
FileStorage

@Component("locfs_FileStorage") public class LocalFileStorage extends Object implements FileStorage
  • Field Details

    • DEFAULT_STORAGE_NAME

      public static final String DEFAULT_STORAGE_NAME
      See Also:
    • storageName

      protected String storageName
    • storageDir

      protected String storageDir
    • properties

      @Autowired protected LocalFileStorageProperties properties
    • coreProperties

      @Autowired protected CoreProperties coreProperties
    • timeSource

      @Autowired protected TimeSource timeSource
    • isImmutableFileStorage

      protected boolean isImmutableFileStorage
    • writeExecutor

      protected ExecutorService writeExecutor
    • storageRoots

      protected volatile Path[] storageRoots
  • Constructor Details

    • LocalFileStorage

      public LocalFileStorage()
    • LocalFileStorage

      public LocalFileStorage(String storageName)
    • LocalFileStorage

      public LocalFileStorage(String storageName, String storageDir)
      Optional constructor that allows specifying storage directory, thus overriding LocalFileStorageProperties.getStorageDir() property.

      It can be useful if there are more than one local file storage in an application, and these storages should be using different dirs for storing files.

  • Method Details

    • getStorageName

      public String getStorageName()
      Description copied from interface: FileStorage
      Returns the name of this storage, which will be saved in FileRefs.

      Each file storage in the application should have a unique name.

      Specified by:
      getStorageName in interface FileStorage
    • createUuidFilename

      protected String createUuidFilename(String fileName)
    • getStorageRoots

      protected Path[] getStorageRoots()
    • saveStream

      public long saveStream(FileRef fileRef, InputStream inputStream)
    • saveStream

      public FileRef saveStream(String fileName, InputStream inputStream, Map<String,Object> parameters)
      Description copied from interface: FileStorage
      Saves an InputStream contents into the file storage using additional parameters.
      Specified by:
      saveStream in interface FileStorage
      Parameters:
      fileName - file name
      inputStream - input stream, must be closed in the calling code
      parameters - additional parameters that can be used in specific storage implementation (for example, can be converted to FileRef parameters)
      Returns:
      file reference
    • createRelativeFilePath

      protected Path createRelativeFilePath(String fileName)
    • openStream

      public InputStream openStream(FileRef reference)
      Description copied from interface: FileStorage
      Returns an input stream to load a file contents.
      Specified by:
      openStream in interface FileStorage
      Parameters:
      reference - file reference
      Returns:
      input stream, must be closed after use
    • removeFile

      public void removeFile(FileRef reference)
      Description copied from interface: FileStorage
      Removes a file from the file storage.
      Specified by:
      removeFile in interface FileStorage
      Parameters:
      reference - file reference
    • fileExists

      public boolean fileExists(FileRef reference)
      Description copied from interface: FileStorage
      Tests whether the file denoted by this file reference exists.
      Specified by:
      fileExists in interface FileStorage
      Parameters:
      reference - file reference
      Returns:
      true if the file denoted by this file reference exists
    • createDateDirPath

      protected Path createDateDirPath()
    • checkFileExists

      protected void checkFileExists(Path path)
    • checkDirectoryExists

      protected void checkDirectoryExists(Path dir)
    • checkPrimaryStorageAccessible

      protected void checkPrimaryStorageAccessible(Path[] roots, String fileName)
    • checkStorageDefined

      protected void checkStorageDefined(Path[] roots, String fileName)
    • setImmutableFileStorage

      public void setImmutableFileStorage(boolean immutableFileStorage)
      This method is mostly needed for compatibility with an old API.

      If isImmutableFileStorage is false then saveStream(FileRef, InputStream) will be overwriting existing files.

    • getRelativePath

      protected Path getRelativePath(String path)
      Converts string path to Path.
    • pathToString

      protected String pathToString(Path path)
      Converts path to a uniform string representation ("yyyy/mm/dd/uuid.ext").
    • stopWriteExecutor

      @PreDestroy protected void stopWriteExecutor()