Package io.jmix.localfs
Class LocalFileStorage
java.lang.Object
io.jmix.localfs.LocalFileStorage
- All Implemented Interfaces:
FileStorage
-
Field Summary
Modifier and TypeFieldDescriptionprotected CoreProperties
static final String
protected boolean
protected LocalFileStorageProperties
protected String
protected String
protected Path[]
protected TimeSource
protected ExecutorService
-
Constructor Summary
ConstructorDescriptionLocalFileStorage
(String storageName) LocalFileStorage
(String storageName, String storageDir) Optional constructor that allows specifying storage directory, thus overridingLocalFileStorageProperties.getStorageDir()
property. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkDirectoryExists
(Path dir) protected void
checkFileExists
(Path path) protected void
checkPrimaryStorageAccessible
(Path[] roots, String fileName) protected void
checkStorageDefined
(Path[] roots, String fileName) protected Path
protected Path
createRelativeFilePath
(String fileName) protected String
createUuidFilename
(String fileName) boolean
fileExists
(FileRef reference) Tests whether the file denoted by this file reference exists.protected Path
getRelativePath
(String path) Converts string path toPath
.Returns the name of this storage, which will be saved inFileRef
s.protected Path[]
openStream
(FileRef reference) Returns an input stream to load a file contents.protected String
pathToString
(Path path) Converts path to a uniform string representation ("yyyy/mm/dd/uuid.ext").void
removeFile
(FileRef reference) Removes a file from the file storage.long
saveStream
(FileRef fileRef, InputStream inputStream) saveStream
(String fileName, InputStream inputStream) Saves an InputStream contents into the file storage.void
setImmutableFileStorage
(boolean immutableFileStorage) This method is mostly needed for compatibility with an old API.protected void
-
Field Details
-
DEFAULT_STORAGE_NAME
- See Also:
-
storageName
-
storageDir
-
properties
-
coreProperties
-
timeSource
-
isImmutableFileStorage
protected boolean isImmutableFileStorage -
writeExecutor
-
storageRoots
-
-
Constructor Details
-
LocalFileStorage
public LocalFileStorage() -
LocalFileStorage
-
LocalFileStorage
Optional constructor that allows specifying storage directory, thus overridingLocalFileStorageProperties.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
Description copied from interface:FileStorage
Returns the name of this storage, which will be saved inFileRef
s.Each file storage in the application should have a unique name.
- Specified by:
getStorageName
in interfaceFileStorage
-
createUuidFilename
-
getStorageRoots
-
saveStream
-
saveStream
Description copied from interface:FileStorage
Saves an InputStream contents into the file storage.- Specified by:
saveStream
in interfaceFileStorage
- Parameters:
fileName
- file nameinputStream
- input stream, must be closed in the calling code- Returns:
- file reference
-
createRelativeFilePath
-
openStream
Description copied from interface:FileStorage
Returns an input stream to load a file contents.- Specified by:
openStream
in interfaceFileStorage
- Parameters:
reference
- file reference- Returns:
- input stream, must be closed after use
-
removeFile
Description copied from interface:FileStorage
Removes a file from the file storage.- Specified by:
removeFile
in interfaceFileStorage
- Parameters:
reference
- file reference
-
fileExists
Description copied from interface:FileStorage
Tests whether the file denoted by this file reference exists.- Specified by:
fileExists
in interfaceFileStorage
- Parameters:
reference
- file reference- Returns:
- true if the file denoted by this file reference exists
-
createDateDirPath
-
checkFileExists
-
checkDirectoryExists
-
checkPrimaryStorageAccessible
-
checkStorageDefined
-
setImmutableFileStorage
public void setImmutableFileStorage(boolean immutableFileStorage) This method is mostly needed for compatibility with an old API.If
isImmutableFileStorage
is false thensaveStream(FileRef, InputStream)
will be overwriting existing files. -
getRelativePath
Converts string path toPath
. -
pathToString
Converts path to a uniform string representation ("yyyy/mm/dd/uuid.ext"). -
stopWriteExecutor
@PreDestroy protected void stopWriteExecutor()
-