FileSystemProvider delegation
Alan Bateman
Alan.Bateman at oracle.com
Thu Apr 28 03:38:38 PDT 2011
Michael Hall wrote:
> I have a 'file' default FileSystemProvider that I am trying in some
> instances to have delegate to the normal platform FileSystemProvider.
> In the getPath(String first, String more) method for the custom
> FileSystem method if it decides to delegate back it currently does this...
>
> In TrueZipFileSystem.java (extends FileSystem)
> getPath(String first, String... more)
> ...
> return new
> PathDelegate(((TrueZipFileSystemProvider)provider).getPriorProvider().getPath(pathURI));
>
> Where PathDelegate is a wrapper for the platform instance Path that
> provides some convenience methods. These are pretty much the
> convenience methods that the zip demo assumes it's Path class to provide.
>
> However, if I try to use this returned platform Path wrapper instance
> like this...
>
> Path absdirfile = Paths.get("/Users");
> System.out.println("Paths absolute dir " + absdirfile + " class " +
> absdirfile.getClass().getName());
> System.out.println(absdirfile + " is directory " +
> Files.isDirectory(absdirfile));
>
> It gets...
>
> Paths absolute dir org.truezip.PathDelegate at cb5de2 class
> org.truezip.PathDelegate
> Exception in thread "main" java.nio.file.ProviderMismatchException
> at sun.nio.fs.UnixPath.toUnixPath(UnixPath.java:200)
> at
> sun.nio.fs.UnixFileSystemProvider.getFileAttributeView(UnixFileSystemProvider.java:128)
> at
> sun.nio.fs.BsdFileSystemProvider.getFileAttributeView(BsdFileSystemProvider.java:57)
> at
> sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:157)
> at
> sun.nio.fs.BsdFileSystemProvider.readAttributes(BsdFileSystemProvider.java:80)
> at java.nio.file.Files.readAttributes(Files.java:1669)
> at java.nio.file.Files.isDirectory(Files.java:2118)
> at BasicSetupTester.main(BasicSetupTester.java:13)
>
> Per the javadoc for ProviderMismatchException
> Unchecked exception thrown when an attempt is made to invoke a method
> on an object created by one file system provider with a parameter
> created by a different file system provider.
>
> So the wrapper class can't be used? It's the only parm. If the
> platform instance will only work with one FileSystem and Path that are
> also platform type, it makes delegation back to it from other
> providers more difficult, doesn't it?
>
What does org.truezip.PathDelegate.getFileSystem().provider() return?
From the stack trace it looks like it is running
sun.nio.fs.BsdFileSystemProvider whereas it should be returning your
file system provider.
If it helps, our test cases have a "pass through" file system that might
be useful to you:
http://hg.openjdk.java.net/jdk7/jdk7/jdk/raw-file/tip/test/java/nio/file/Files/PassThroughFileSystem.java
-Alan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20110428/b4ba14dd/attachment.html
More information about the nio-dev
mailing list