Zip file system provider only works with default file system
Philippe Marschall
philippe.marschall at gmail.com
Fri Dec 7 15:05:49 PST 2012
Hi
First, I hope I got the right mailing list. I'm in the process of
writing my own file system provider. As a test I wanted to create a
zip file on it using the zip file system provider. That's when I
discovered that it only works with the default file system.
The culprit is the following method in ZipFileSystem:
// Creates a new empty temporary file in the same directory as the
// specified file. A variant of File.createTempFile.
private Path createTempFileInSameDirectoryAs(Path path)
throws IOException
{
Path parent = path.toAbsolutePath().getParent();
String dir = (parent == null)? "." : parent.toString();
Path tmpPath = File.createTempFile("zipfstmp", null, new
File(dir)).toPath();
tmppaths.add(tmpPath);
return tmpPath;
}
I unnecessarily uses File.createTempFile when Files.createTempFile
would be available as an alternative that works with every file system
provider. I assume something like this should work.
// Creates a new empty temporary file in the same directory as the
// specified file. A variant of Files.createTempFile.
private Path createTempFileInSameDirectoryAs(Path path)
throws IOException
{
Path parent = path.toAbsolutePath().getParent();
Path dir = (parent == null)? path.getFileSystem().getPath(".") : parent;
Path tmpPath = Files.createTempFile(dir, "zipfstmp", null);
tmppaths.add(tmpPath);
return tmpPath;
}
I did not actually build a JDK and test this code.
Cheers
Philippe
More information about the nio-dev
mailing list