JGenFile Java Generic Filesystems

Latest Version:
JGenFile 1.0 alpha

Features

JGenFile is a set of interfaces designed for working with various file systems in Java. It provides a much more powerful alternative to using java.io.File objects.

Description
When speaking of a file system in regards to JGenFile, a file system is simply a collection of files and directories that are somehow connected to each other. For example, a file will exist inside a directory which will have parent directories.

File System Support
JGenFile will eventually allow access to different file systems, such as FTP file systems, ZIP files and more. Of course there is no stopping others from writing additional file system implementations and plugging them in.

Metadata
JGenFile supports any metadata items in a file system can have. An example of metadata is the last modified date of a file. Different file systems support different metadata. JGenFile supports access to whatever metadata is available for an item.

Efficiency
JGenFile has the ability to optimize multiple operations. For example, if you need to get the last modified date of every file in a directory, the file system implementation may be able to optimize these operations to increase efficiency. An FTP file system, for example, might be able to get all its information in one command from the server

Likewise, if a ZIP file system implementation has to delete a file, the entire ZIP file may have to be rewritten. Therefore if 10 files need to be deleted at once on a file system it can optimize the delete commands so that only one ZIP file rewrite would be required instead of 10.

Links
Some file systems support soft links, or shortcuts to other files. JGenFile supports the idea of these links, allowing the target of a link to be read in programatically if the file system supports links.

How to use JGenFile
Well, it's not finished yet so you can't use it :-) But this is how you would use it if it were finished.

Let's take an example of a text editing program. Pretty simple, takes an input file, displays text, saves modifications to file.

To open a file, the normal way to do things would be to bring up a dialog to allow the user to select a file to open. From this dialog you get a java.io.File object. You create a FileInputStream or FileReader or a FileChannel, and then read data from it.

With JGenFile, a different dialog would be displayed allowing the user to select a file. This dialog would allow the user to change to different file systems other than the local one, using whatever providers are installed for JGenFile. You get back a JGenFile File object. From here you create a CreateFileAccessorOperation using the createCreateFileAccessorOperation() method of File. You simply run() this operation and get back the appropriate byte channel (yes JGenFile uses java.nio). If you need an InputStream instead, you can use the utility class in the java.nio package to convert a ByteChannel to an InputStream. Then read data in like normal.

At first it might appear that JGenFile is unnecessarily complex, but it is required to support different file systems efficiently. But by converting your application to use JGenFile you have just allowed users to open files directly from inside ZIP archives, FTP sites and more depending on what file system providers are installed for JGenFile.