aboutsummaryrefslogtreecommitdiff
path: root/src/share/demo/nio
diff options
context:
space:
mode:
authorsherman <none@none>2011-02-11 12:20:45 -0800
committersherman <none@none>2011-02-11 12:20:45 -0800
commit446871d4c9e4d68ad6564135bddd03a9d1829bb9 (patch)
treeace466a60e46a9e6f94754ed1268f9766eb79344 /src/share/demo/nio
parent764e4c2cf131bfe03ec09b66bc4b3b4da6e476bb (diff)
downloadjdk8u_jdk-446871d4c9e4d68ad6564135bddd03a9d1829bb9.tar.gz
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
Summary: updated newFileSystem() to throw UOE exception for non-zip/jar file Reviewed-by: alanb
Diffstat (limited to 'src/share/demo/nio')
-rw-r--r--src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystemProvider.java64
1 files changed, 43 insertions, 21 deletions
diff --git a/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystemProvider.java b/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystemProvider.java
index 60c8fed929..d8aa305d29 100644
--- a/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystemProvider.java
+++ b/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystemProvider.java
@@ -42,6 +42,7 @@ import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import java.util.zip.ZipError;
import java.util.concurrent.ExecutorService;
/*
@@ -78,43 +79,64 @@ public class ZipFileSystemProvider extends FileSystemProvider {
}
}
- @Override
- public FileSystem newFileSystem(URI uri, Map<String, ?> env)
- throws IOException
- {
- return newFileSystem(uriToPath(uri), env, true);
- }
-
- @Override
- public FileSystem newFileSystem(Path path, Map<String, ?> env)
- throws IOException
- {
- if (!path.toUri().getScheme().equalsIgnoreCase("file")) {
- throw new UnsupportedOperationException();
+ private boolean ensureFile(Path path) {
+ try {
+ BasicFileAttributes attrs =
+ Files.readAttributes(path, BasicFileAttributes.class);
+ if (!attrs.isRegularFile())
+ throw new UnsupportedOperationException();
+ return true;
+ } catch (IOException ioe) {
+ return false;
}
- return newFileSystem(path, env, false);
}
- private FileSystem newFileSystem(Path path, Map<String, ?> env, boolean checkIfFSExists)
+ @Override
+ public FileSystem newFileSystem(URI uri, Map<String, ?> env)
throws IOException
{
+ Path path = uriToPath(uri);
synchronized(filesystems) {
Path realPath = null;
- if (checkIfFSExists && Files.exists(path)) {
+ if (ensureFile(path)) {
realPath = path.toRealPath(true);
if (filesystems.containsKey(realPath))
throw new FileSystemAlreadyExistsException();
}
- ZipFileSystem zipfs = new ZipFileSystem(this, path, env);
- if (realPath == null)
- realPath = path.toRealPath(true);
- if (!filesystems.containsKey(realPath))
- filesystems.put(realPath, zipfs);
+ ZipFileSystem zipfs = null;
+ try {
+ zipfs = new ZipFileSystem(this, path, env);
+ } catch (ZipError ze) {
+ String pname = path.toString();
+ if (pname.endsWith(".zip") || pname.endsWith(".jar"))
+ throw ze;
+ // assume NOT a zip/jar file
+ throw new UnsupportedOperationException();
+ }
+ filesystems.put(realPath, zipfs);
return zipfs;
}
}
@Override
+ public FileSystem newFileSystem(Path path, Map<String, ?> env)
+ throws IOException
+ {
+ if (path.getFileSystem() != FileSystems.getDefault()) {
+ throw new UnsupportedOperationException();
+ }
+ ensureFile(path);
+ try {
+ return new ZipFileSystem(this, path, env);
+ } catch (ZipError ze) {
+ String pname = path.toString();
+ if (pname.endsWith(".zip") || pname.endsWith(".jar"))
+ throw ze;
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
public Path getPath(URI uri) {
String spec = uri.getSchemeSpecificPart();