Mr. Awellstein
Mr. Awellstein

Reputation: 157

Creating a custom FileSystem implementation in Java

I read on oracle that it is possible to create a custom FileSystem, but I can't really find much documentation on creating one. Could anyone link me to somewhere I can learn more about custom FileSystems?

Where I read about this: http://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/filesystemprovider.html

Upvotes: 12

Views: 14602

Answers (3)

BhaskarG
BhaskarG

Reputation: 31

I know this is an old question but many people still want the actual answer, which is not here. The problem is that the documentation by Oracle (Sun), listed by the OP is missing critical information. What adds to the confusion is that the "demo" referenced by the doc is packaged in a confusing way. There is a Demo.java source file and src.zip and a zipfs.jar. The Demo.java is NOT a FileSystemProvider. Its a custom FileSystem. For it to work you have to add the zipfs.jar to the "extensions" folder of your JRE/JDK, so that when the Demo.getZipFSProvider() method is called, it will find the custom FileSystemProvider which returns the custom FileSystem. If you look in the src.zip you will find the code for the provider. If the Java documentation had been properly written this question would not have come up. Its confusing. Even the readme file in the demo makes no mention of the provider. Sad.

Upvotes: 2

btiernay
btiernay

Reputation: 8129

A (Real) Simple Example

A very simple Java FileSystem to use as an example is nodet/githubfs. There are only a few classes and it will give you the flavor of how to implement a basic file system. The primary classes are:

Note that this file system does not implement all operations (which is part of the reason it is good as a high level example).

Experiment!

To experiment with using a custom FileSystem without any coding, a handy project is puniverse/javafs. It allows you to mount it as a FUSE and interact with it from a terminal. Setup is quite easy:

import co.paralleluniverse.javafs.JavaFS;
...
// Need to mkdir /tmp/mnt first
JavaFS.mount(fileSystem, Paths.get("/tmp/mnt"));
Thread.sleep(Long.MAX_VALUE);

Upvotes: 16

rboyer
rboyer

Reputation: 376

Google opensourced a completely in-memory filesystem implementation called JimFS: https://github.com/google/jimfs

Upvotes: 9

Related Questions