This module provides a set of generic base classes to make it easier to write your own FileSystemProvider. The ax-fileystem-memory module is a usable, working example of how to use this module. While this module is licensed under Apache 2.0, the ax-fileystem-memory license is less restrictive so that you may copy it.
So you want to create a FileSystemProvider... That's one of the main reasons we created ax-fileystem-memory, and this module, on which that one is built.
You've probably seen the guide from oracle or any number of pieces of example code.
The critical thing missing from many of these pages is fully-fledged example code.
The oracle guide refers to the ZipFileSystemProvider
which you probably wouldn't want to copy, and other examples like githubfs are implementation specific enough that they would be hard to copy.
ax-fileystem-memory is simple, and we have tried to create a maximum of re-usable code in a this module. Here are the rough steps we suggest when you want to create your own filesystem provider:
- Take a look at the the javadocs for the classes you will need to implement:
- At least skim the guide from oracle so you understand terms.
- Set up your project
- Create your maven module
- Add a dependency on
com.g2forge.alexandria:ax-filesystem
so you can use our generic base classes - Add a test scoped dependency on
com.g2forge.alexandria:ax-filesystem-test
so you can use our file system unit tester (test driven development is most fun when someone else writes the tests)
- Copy the unit tests in your
src/test/java
package
- Modify the
before()
method to create an instance of your file system - Modify the
createPath()
method to create paths associated with the file system created bybefore()
- Depending on how you decide to format your URIs, you may only need to update
MYFS
to your scheme (replacememory:...
withMYFANCYNEWFS:...
).
- Run JUnit and watch everything fail because you haven't implemented anything. This'll make it more fun later when you implement things.
- Create your
FileSystemProvider
by extendingAGenericFileSystemProvider
- You can copy MemoryFileSystemProvider
- At a minimum you'll need to change the
getScheme()
return value to your new scheme. This way you'll have a fully functional memory file system provider, separate from ours.
- At a minimum you'll need to change the
- You may find it easier to start from an empty class and fill in implementations, watching your unit test pass rate increase as you go.
MemoryFileSystemProvider
is implemented using AGenericFileSystemProvider
.
This means you will need to implement:
- A class for URIs
- All the basic file system operations like
createDirectory()
,delete()
, etc. - Some kind of code to represent entries, files and directories in your file system, and
IGenericEntryAccessor
to allow the base classes to interact with this. - File attributes using
IAttributeViewAccessor
You will not need to implement:
FileSystem
, though you can write a custom one the easiest way will be to useGenericFileSystem
Path
, though you can write a custom one the easiest way will be to useGenericPath
- Code to handle locking and atomicity, or basic file time modifications