Package com.coreoz.plume.file.services
Class FileService
- java.lang.Object
-
- com.coreoz.plume.file.services.FileService
-
@Singleton public class FileService extends Object
-
-
Constructor Summary
Constructors Constructor Description FileService(FileMetadataService fileMetadataService, FileStorageService fileStorageService, FileMimeTypeDetector fileMimeTypeDetector, FileConfigurationService fileConfigurationService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringadd(FileType fileType, InputStream fileData)Consume the stream to produce a byte array, then calladd(FileType, InputStream, String)Stringadd(FileType fileType, InputStream fileData, String fileName)Consume the stream to produce a byte array, then calladd(FileType, InputStream, String, String, String)Stringadd(FileType fileType, InputStream fileData, String fileName, String mimeType)Consume the stream to produce a byte array, then calladd(FileType, InputStream, String, String, String)Stringadd(FileType fileType, InputStream fileInputStream, String originalName, String fileExtension, String mimeType)Save a new filevoiddeleteFilesForDeletedTypes()Delete files having a type that longer exists in theFileTypeenum and can't be linked to stored files.voiddeleteUnreferenced()Delete unreferenced files.Optional<InputStream>fetchData(String fileUniqueName)Optional<FileMetadata>fetchMetadata(String fileUniqueName)
-
-
-
Constructor Detail
-
FileService
@Inject public FileService(FileMetadataService fileMetadataService, FileStorageService fileStorageService, FileMimeTypeDetector fileMimeTypeDetector, FileConfigurationService fileConfigurationService) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
-
Method Detail
-
add
public String add(FileType fileType, InputStream fileInputStream, String originalName, String fileExtension, String mimeType) throws UncheckedIOException
Save a new file- Parameters:
fileType- the type of the fileFileTypefileInputStream- the file data stream, that will be closed automatically in this methodoriginalName- the optional (nullable) original name of the file. This won't be the name under the one the file will be savedfileExtension- the optional (nullable) file extensionmimeType- the optional (nullable) mime type- Returns:
- the unique file name of the file. This will be the name under the one the file will be saved
- Throws:
UncheckedIOException- in case the file could not be saved
-
add
public String add(FileType fileType, InputStream fileData) throws UncheckedIOException
Consume the stream to produce a byte array, then calladd(FileType, InputStream, String)- Throws:
UncheckedIOException
-
add
public String add(FileType fileType, InputStream fileData, String fileName, String mimeType) throws UncheckedIOException
Consume the stream to produce a byte array, then calladd(FileType, InputStream, String, String, String)- Throws:
UncheckedIOException
-
add
public String add(FileType fileType, InputStream fileData, String fileName) throws UncheckedIOException
Consume the stream to produce a byte array, then calladd(FileType, InputStream, String, String, String)- Throws:
UncheckedIOException
-
fetchData
public Optional<InputStream> fetchData(String fileUniqueName)
-
fetchMetadata
public Optional<FileMetadata> fetchMetadata(String fileUniqueName)
-
deleteUnreferenced
public void deleteUnreferenced() throws UncheckedIOExceptionDelete unreferenced files.- Throws:
UncheckedIOException- is a file could not be deleted. It is possible to retry if the deletion failed.
-
deleteFilesForDeletedTypes
public void deleteFilesForDeletedTypes() throws UncheckedIOExceptionDelete files having a type that longer exists in theFileTypeenum and can't be linked to stored files. This method should be used punctually only when a file type is deleted. Else unwanted files could be deleted in a shared metadata database environment.- Throws:
UncheckedIOException- if a file could not be deleted. This may happen if the file storage service cannot delete the file. It is possible to retry if the deletion failed.
-
-