FileSystemProvider example....

Michael Hall mik3hall at gmail.com
Tue Jun 26 03:57:29 PDT 2012


On Jun 26, 2012, at 4:07 AM, Alan Bateman wrote:

> On 26/06/2012 04:18, Tom Lasseter wrote:
>> 
>>  
>>  
>> The new Java 7 FileSystem is very cool….just what I need…but for the life of me I can’t create a custom FileSystemProvider.  There must be an example somewhere!  There is only the ZipFileSystemProvider.  I want to create a new FileSystem on either my local system or on a remote system. 
>>  
>> The simplest case is given the local system as the DefaultFileSystemProvider, I want a new FileSystem from it rooted at some arbitrary path, like c:/FileSystems/myFileSystem.  What could be easier than that given the technology being provided.  I would think that this would do it:
>>  
>> Map<String, String> env = new HashMap<>();
>> env.put("create", "true");
>> Path path = Paths.get(“c:/FileSystems/myFileSystem”);
>> FileSystem fileSystem = null;
>> try
>> {
>> fileSystem = fileSystemProvider.newFileSystem(path, env);
>> }
>> catch(Exception e)
>> {
>>                e.printStackTrace();
>> }
>>  
>> Help would be appreciated. 
>>  
>> Thanks and regards,
>>  
>> Tom
>>  
>> 

Possibly helpful.
Developing a Custom File System Provider
http://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/filesystemprovider.html

> Developing your own file system implementation is non-trivial, there is quite a bit of work to do it right.  The zip provider is the example provider that we include in the JDK, you'll find the source code in the $JDK_HOME/demo/nio/zipfs directory. Sorry, we don't include any others at this time but there are folks on this list that may be able to share their experiences.
> 
> In this API then FileSystems.getDefault() will give you a reference to the FileSystem for your local file system. This can be used to access of the volumes that you have mounted, be they local or remote file systems.
> 
> If I understand your mail correctly then you're looking to create a chroot like environment. One idea is to grab the PassThroughFileSystem that you'll find in the test sources and then hack on it so that you get to a relative path that can be resolved against whatever root you want. You'll also need to get the eventual real path to deal with sym links and other cases that would escape into other areas of the default file system. A fun project.

Starting with a PassThroughFileSystem implementation allows a incremental or more piecemeal approach.You don't have to change everything the zip demo does. You can change only the parts of interest. Then later improve that support or add support for something else.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20120626/c735271c/attachment-0001.html 


More information about the nio-dev mailing list