Legacy java.io.File and new FileSystems
Michael Hall
hallmike at att.net
Sat Aug 14 16:21:58 PDT 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Aug 11, 2010, at 7:26 AM, Alan Bateman wrote:
> The API allows the default provider to be replaced and also
> supports providers that want to layer themselves over the default
> provider. You'll find the details in the javadoc.
>
Sorry, I'm trying not to take too much time on what may not be seen
as an important feature. However, this still seems to have
limitations with regard to legacy code.
If as indicated in the javadoc I start with
- -Djava.nio.file.spi.DefaultFileSystemProvider=<a custom file system
provider>
and run a simple program that does
new java.io.File("TestFSP.java").exists();
with verbose classloading it shows no nio is involved.
It appears to get java.io.FileSystem and java.io.UnixFileSystem only.
if I change the program to
new java.io.File("TestFSP.java").toPath().exists();
nio does get loaded and my custom FileSystem is passed the exists()
invocation.
Again, this leaves no way to get unmodified File based legacy code to
use the new FileSystem API. This doesn't seem to be a limitation of
the File class. The same system property check that Path apparently
does somewhere could be done in the java.io.FileSystem.getFileSystem
invocation? Or even locally File.exists could do a toPath().exists(),
unless there's some worry this might in some instances change legacy
behavior in unanticipated and unwanted ways.
Also, I haven't got that far, but assuming it would be possible to
provide an alternate legacy provider for the 'file' scheme, I might
not always want it to handle all instances. For example if it was a
zip provider and the path was my.path.to.zip.and.to.entry my provider
would want to handle it. If was to a.non.pkzip.file.entirely.txt,
then I would want to pass it to the default provider. Some way to
delegate non-handled to the default or some other provider would be
good? If use of the system property erases the only reference to the
default platform 'file' provider during launching this wouldn't be
possible.
Mike Hall hallmike at att dot net
http://www195.pair.com/mik3hall
http://www195.pair.com/mik3hall/home.html
http://sourceforge.net/projects/macnative
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
iJwEAQECAAYFAkxnJRwACgkQUvk/ZSaThTKzogP/VFRDx1245u/wk/9U0QnCVrkm
mwNMdJHkIdN43j5UPHVA7dRekOwQzij4hsn5avWHKnFINh3vvD7Mo9VJ48h1rHfN
uDOstzSbiIm5ZPz2WNw8xVXNVjPaosryPdxWWseWhyE/LxI8wCQ4ugy5bt5eSXCS
R0gYuOV04j2jYOqAZi8=
=E+wE
-----END PGP SIGNATURE-----
More information about the nio-discuss
mailing list