Copyright © 2014-2015
Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
The FileManagerModule provides an abstraction layer for storing and retrieving files in an efficient way. Files are uniquely identified using a FileDescriptor and stored in a named FileRepository. Clients access all files and repositories through the central FileManager bean.
By default the FileManagerModule sets up local directory based file repositories and requires very little configuration.
Module website: https://foreach.atlassian.net/wiki/display/AX/FileManagerModule
<dependencies> <dependency> <groupId>com.foreach.across.modules</groupId> <artifactId>file-manager-module</artifactId> <version>1.0.0.RELEASE</version> </dependency> </dependencies>
Initial public release available on Maven central.
The default configuration of the FileManagerModule will automatically create file based repositories in a single root folder (controller by the fileManagerModule.localRepositoriesRoot property). A new repository will be created when it is accessed for the first time. If no explicit repository id is specified for file access, default will be used.
Files are identified by a unique
FileDescriptor that determines in which backing
FileRepository a file should be saved or from which it should be retrieved.
FileDescriptor has a URI property that is a globally unique
String version of the descriptor.
FileDescriptor can be serialized to and from its URI.
FileRepository is identified by a unique repository id.
The first part of a
FileDescriptor will always contain the repository id.
FileRepository stores its files is implementation dependent.
This could be disk-based storage, database backed or any form of cloud storage.
The purpose of the
FileRepository interfaces is to provide a flexible way for modules to interact with files, without knowing how or where they are actually persisted.
FileManager service bean (exposed) is the facade to access any
It is the central interface that clients should use for accessing files.
Using it is pretty straightforward, the interface methods are well-documented and fairly self-explanatory.
// Create a new temporary file File tempFile = fileManager.createTempFile(); // Write data to the temporary file writeUploadedImage( tempFile ); // Move the file into the 'images' repository (this deletes the temp file) FileDescriptor fd = fileManager.moveInto( "images", tempFile ); // Store the unique file descriptor in database imageRecord.setFileUri( fd.getUri() );
Registering your own
FileRepository can be done through the (exposed)
The default implementation will wrap all repositories in a
Consumers can request a hard reference to a specific
FileRepository using the
Because they actually get a
FileRepositoryDelegate reference, the actual implementation can be modified at runtime through the repository registry.
The FileManagerModule has the following
Simple implementation that stores all files a single root directory.
pathGenerator property is set, the
PathGenerator instance will be used to generate a sub-directory structure to store the files in.
DateFormatPathGenerator is a default implementation that uses the current date for creating sub-directories.
PathGenerator can help distribute the physical files, avoiding OS performance problems when there are too many files in a single directory.