Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
# FileSystemFacade
A facade to different file system types such as Native (like, in memory, database, server, SFTP history, sub-directory and encrypted as well as combinations of these.
Created 2017-2020 by Philip Heyse
## Featuers
- FileSystemFacade (FSF) allows you to write unit tests simulating the regular file system in memory. All tests can run in parallel without any interference. With the change of one line of code / calling a different init-method the actual native file system ( is used
- Instead of a normal local file system, the files may also be located in a database on a different server (RemoteFS) which is called via a Java servlet. The behavior of the file system stays the same
- Additional features can be added to the file system by basing one file system onto another.
- File systems may be encrypted by using EnryptionFS with a different inner file system (e.g. NativeFS, MemoryFS, DatabaseFS, RemoteFS)
- File systems may have version logic by using HistroyFS with a different inner file system. Each file then has a version property and you can enforce that only the next version of a file may be written - avoiding cases where two different instances each attempt to write the next version causing data inconsistencies.
- File systems may have a limited or infinite number of history entries each time a file or directory is changed or deleted, also by using HistoryFS.
- File systems may be limited to only a specific sub-directory to provide an app from writing "outside" of it's designated data folder in case of a malfunction or an attack.
- It is possible to copy from one file system to another. Examples: copy from MemoryFS to the NativeFS after a failed unit test, copy from RemoteFS or DatabaseFS to a NativeFS for backup.
## Usage
### Native file system with behavior similar to
FSFSystem fs = new NativeFS();
FSFFile myDir = fs.createByPath("C:\data\my_dir");
FSFFile myTextFile = myDir.getChild("myText.txt");
String text = myTextFile.readString(); //: read file as UTF-8 text
### In-memory file system
FSFSystem fs = new MemoryFS();
FSFFile myDir = fs.createByPath("/data/my_dir");
FSFFile myTextFile = myDir.getChild("myText.txt");
String text = myTextFile.readString(); //: read file as UTF-8 text
### Operations with different file systems
private static fianl int FSF_TYPE = 3;
public FSFFile getAppDir(int type) throws Exception {
String password = "myPassword";
switch (type) {
case 1:
return new NativeFS().createByPath("C:\\my_data\\app1");
case 2:
return new NativeFS().createByPath("/usr/local/app1");
case 3:
return new MemoryFS().createByPath("/data");
case 4:
FSFSystem innerFS = new MemoryFS();
return new EncryptedFS(innerFS, password, "/data").createByPath("/encrypetd");
case 5:
new RemoteFS("/", "myApp", "myTennant", "myUser", "myPassword", "").createByPath("/data");
case 6:
new DatabaseFS(createDatabaseConfig()).createByPath("/data");
case 7:
new HistoryFS(new MemoryFS(), true).createByPath("/data");
case 8:
new HistoryFS(new NativeFS(), true).createByPath("C:\\my_data\\app1");
case 9:
new SubDirFS(new NativeFS(), "/usr/local/app1").createByPath("/");
case 10:
SftpFSConfig config = new SftpFSConfig();
new new SftpFS(SftpFS.Mode.VFS, config, "/myuser_dir").createByPath("/myuser_dir/data");
throw new Exception("Unexpected type: " + type);
public void static void main(String[] args){
// depending on the type constant a different file system type is returned.
FSFFile appDir = getAppDir(FSF_TYPE);
// all following actions can be performed whichever file system type was chosen:
FSFFile file = appDir.getChild("MyFile.txt").writeString("nice");
List<FSFFile> allFiles = appDir.listFilesTree();
for (FSFFile i: allFiles){
System.out.println("Name = '" + i.getName() + "'");
System.out.println("Path = '" + i.getAbsolutePath() + "'");
System.out.println("Length = '" + i.getLength() + "'");
## Maven Dependencies
### Core Library (memory, database, server, sub-directory and encrypted, etc.)
### SFTP Library
## Building and testing
In the "mvn clean package" in root dir of parent-pom which is "framework/FSF-ParentPOM". To run the integration-test (which require DB connection, a remote connection, write to local file system) execute Maven goal: "integration-test" and provide settings in directory ".FileSystemFacade_test_config" in the user-dir.
## Project Structure
- There is one parent POM located in "framework/FSF-ParentPOM".
- "framework/FSF-Core" contains the core library incl. memory, database, server, sub-directory and encrypted, etc.
- "framework/FSF-CommonTests" contains the test which can be used by the core as well as other modules. In order to make these tests re-usable they are included in the jar and not just in the test-scope.
- "framework/FSF-ApacheVFS" contains a facade to Apache Commons VSF. It may also be extended to support other file system types such as Hadoop. It is based on the core library and uses the FSF-CommonTests.
- "framework/FSF-SFTP" contains the support for SFTP based on FSF-ApacheVFS.
## Change History
Version 2.3.0 (2019-08-03)
- encryption via the BEAM module
Version 2.4.0 (2019-08-07)
- added feature SubDirFS
Version 2.4.1 (2019-08-20)
- with RemoteFS allows copyTo to a different FS
Version 2.4.2 (2019-08-20)
- bugfix copy files tree for history FS
Version 2.5.0 (2019-09-06)
- EncryptedFS allows versions and works with inner RemoteFS
Version 2.5.1 (2019-09-07)
- EncryptedFS performance improvement - especially for RemoteFS
Version 2.5.2 (2019-09-12)
- updated to BEAM 1.0.1 which does not need external XML library to read/write hex-string and works with Android
Version 2.6.0 (2019-09-13)
- RemoteFS allow reading file history
Version 2.6.1 (2019-10-21)
- set dependency of mariadb-java-client to scope "test" in pom.xml to aviod problems when including in Android
Version 2.7.0 (2020-05-04)
- Restructured project into different sub-projects
- added "bridge" to Apache Commons VFS
- added support for SFTP