Virtual filesystem
One interesting question I had at my Java 7 talk this past weekend was whether JSR 203 would support an in-memory virtual filesystem. Interestingly, this is exactly the same question the first time I read the JSR 203 spec. A virtual filesystem will not be included as part of JSR 203 but certainly the API is designed to be extensible and all of the hooks exist to provide such an implementation.
Alan Bateman mentioned that using direct buffers for file storage would be an excellent choice as it would provide for large virtual file systems without actually using large amounts of Java heap.
So, if anyone’s looking for a cool (and useful) open source project, this would be a great one. Having a virtual memory system to plug into would be fantastic for unit testing. You could create files to your heart’s content and the file access would be fast while also saving you from all the annoying issues with deleting temporary files, Windows file locking, etc. Go to it, lazyweb!

Hi! My name is Alex Miller and I live in St. Louis. I write code for a living and currently work for
As we didn’t (and still don’t) have JSR 203 two years ago, we started with a similar framework for our (commercial) product. I think, the ideas of how to build the interfaces are quite close to what JSR 203 now comes up with. One of the important things to consider was the user of the filesystem not having any idea of what is behind the filesystem-objects he or she is using: Either a real or virtual filesystem, or maybe a remote filesystem (hiding a proprietary or ftp-like connection underneath). I didn’t check for JSR 203 to provide all the required attributes, but I’d definitely like to see a project, too, providing additional and useful filesystem implementations.
In the meantime, why not use Commons VFS ? It supports both temporary files and ram files emulation.
I absolutely agree with your comments on the memory filesystem. Its absence is a bit puzzling in light of its usefulness and educational value.
Other potential filesystems of value would be those that wrap another file system to add capabilities. A caching filesystem could wrap both the memory one and a slow network-based one for example. Filesystems have lots of potential features that could be implemented in such a layered way. Transparent journaling, versioning, compression, and archiving are similar layered facilities.
Good comments all. I can also see filesystems for zip/jar archives, storage in the cloud, and other such useful impls.
It would be good to include a good memory file system implementation. If someone has the cycles to do this and contribute it that would be great. I agree it would be useful from an educational perspective. It may also be useful when running on operating systems that don’t have /tmp or equivalent on swap. In the demo directory there is a read-only zip/JAR provider (contributed by Rajendra Gutupalli).
There’s the JBoss Microcontainer VFS project:
MC site: http://www.jboss.org/jbossmc/
VFS code: http://anonsvn.jboss.org/repos/jbossas/projects/vfs/trunk/
You can use VFS without the whole container, easily enough.
It’s a bit painful (to say the least), but you can use the Java instrumentation API (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/instrument/package-summary.html) to reinstrument the classes that handle IO (for example FileInputStream/FileOutputStream/File/FileReader/FileWriter/etc…) to use a class that implements the same api, but supports an in-memory file system by using an alternate base directory, e.g. ‘/in-memory/’.
But I do admit that the new JSR is a better alternative, as long as the current IO and NIO packages are reengineered to use it in the background (otherwise implementing an in-memory FS would be a pain if you have code which uses the old IO APIs – you would have to rewrite all the code to use the new APIs just to be able to use an in-memory FS).
I would like to know how to create a virtual file system using java. Please comment…..