Legacy java.io.File and new FileSystems

Michael Hall hallmike at att.net
Sun Aug 15 12:03:55 PDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Aug 15, 2010, at 1:27 PM, Alan Bateman wrote:

>> It might be needed in some cases to check for the presence of a  
>> custom provider and do the toPath() route. For consistency maybe  
>> even always do this taking the custom provider property as an  
>> indication that they want to use the new API.
> I don't think I understand what you mean but but once there is a  
> custom provider set as the default then it will need to be invoked  
> for all access to the file system.


What I had been thinking was that java.io.File support would go  
something like FileSystem.getFileSystem gets a instance for the  
platform or custom FileSystem, whichever it is. But since there are  
slight differences between io.FileSystem and nio.FileSystem like the  
getBooleanAttributes usage then this wouldn't work for anything like  
the exists() method I was testing with.
For exists() you could test if a custom provider was in effect,  
meaning nio, and then do what was successful for me. toPath().exists 
() and what getFileSystem had returned wouldn't matter.
Although I haven't verified that there is an equivalent Path method  
for each File method I'm assuming so.
Then File support might better be something like...

package java.io;

public class File {

public boolean exists() {
	SecurityManager security = System.getSecurityManager();
	if (security != null) {
		security.checkRead(path);
	}
	if (custom)		// Was a custom nio FileSystemProvider indicated?
		return toPath().exists();
	// No use platform 'io' provider
	return ((fs.getBooleanAttributes(this) & FileSystem.BA_EXISTS) != 0);
}

all done? Any differences in the FileSystem API's io to nio don't  
matter as long as File and Path aren't different.

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)

iJwEAQECAAYFAkxoOiEACgkQUvk/ZSaThTJWCAP/YoYIFFbweleT0i5yHQgn0ywb
2sXiJiNZpqOMrcYPAzchmbjc7ZwcqRwxwY1HLY9aKhIVQhlALX7xiSHFMoxu7iQt
IZ9PD1+u1tT4MoOJCH48+rZQicSkPSSeeLV3uV2CiyOAeWAZLmz9wQa+6N/SrD3z
sq8vrnnHMD8XFTh5rCQ=
=KWAj
-----END PGP SIGNATURE-----


More information about the nio-discuss mailing list