author | vromero |
Tue, 20 Feb 2018 11:45:16 -0500 | |
changeset 48920 | 916690b5edc9 |
parent 47216 | 71c04702a3d5 |
child 51787 | ba51515b64e5 |
permissions | -rw-r--r-- |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1 |
/* |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
2 |
* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
4 |
* |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
10 |
* |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
15 |
* accompanied this code). |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
16 |
* |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
20 |
* |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
23 |
* questions. |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
24 |
*/ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
25 |
|
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
26 |
package jdk.nio.zipfs; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
27 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
28 |
import java.io.*; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
29 |
import java.nio.channels.*; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
30 |
import java.nio.file.*; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
31 |
import java.nio.file.DirectoryStream.Filter; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
32 |
import java.nio.file.attribute.*; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
33 |
import java.nio.file.spi.FileSystemProvider; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
34 |
import java.net.URI; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
35 |
import java.net.URISyntaxException; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
36 |
import java.util.HashMap; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
37 |
import java.util.Map; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
38 |
import java.util.Set; |
28562
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
25859
diff
changeset
|
39 |
import java.util.zip.ZipException; |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
40 |
import java.util.concurrent.ExecutorService; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
41 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
42 |
/* |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
43 |
* |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
44 |
* @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
45 |
*/ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
46 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
47 |
public class ZipFileSystemProvider extends FileSystemProvider { |
7189 | 48 |
|
49 |
||
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
50 |
private final Map<Path, ZipFileSystem> filesystems = new HashMap<>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
51 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
52 |
public ZipFileSystemProvider() {} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
53 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
54 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
55 |
public String getScheme() { |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
56 |
return "jar"; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
57 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
58 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
59 |
protected Path uriToPath(URI uri) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
60 |
String scheme = uri.getScheme(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
61 |
if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
62 |
throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
63 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
64 |
try { |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
65 |
// only support legacy JAR URL syntax jar:{uri}!/{entry} for now |
12430
bd6e432b84ad
7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
11841
diff
changeset
|
66 |
String spec = uri.getRawSchemeSpecificPart(); |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
67 |
int sep = spec.indexOf("!/"); |
32306
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
28562
diff
changeset
|
68 |
if (sep != -1) { |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
69 |
spec = spec.substring(0, sep); |
32306
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
28562
diff
changeset
|
70 |
} |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
71 |
return Paths.get(new URI(spec)).toAbsolutePath(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
72 |
} catch (URISyntaxException e) { |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
73 |
throw new IllegalArgumentException(e.getMessage(), e); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
74 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
75 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
76 |
|
8386
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
77 |
private boolean ensureFile(Path path) { |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
78 |
try { |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
79 |
BasicFileAttributes attrs = |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
80 |
Files.readAttributes(path, BasicFileAttributes.class); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
81 |
if (!attrs.isRegularFile()) |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
82 |
throw new UnsupportedOperationException(); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
83 |
return true; |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
84 |
} catch (IOException ioe) { |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
85 |
return false; |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
86 |
} |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
87 |
} |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
88 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
89 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
90 |
public FileSystem newFileSystem(URI uri, Map<String, ?> env) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
91 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
92 |
{ |
8386
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
93 |
Path path = uriToPath(uri); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
94 |
synchronized(filesystems) { |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
95 |
Path realPath = null; |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
96 |
if (ensureFile(path)) { |
9025
a72fc1fc4b71
7029979: (fs) Path.toRealPath(boolean) should be toRealPath(LinkOption...)
alanb
parents:
8386
diff
changeset
|
97 |
realPath = path.toRealPath(); |
8386
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
98 |
if (filesystems.containsKey(realPath)) |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
99 |
throw new FileSystemAlreadyExistsException(); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
100 |
} |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
101 |
ZipFileSystem zipfs = null; |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
102 |
try { |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
103 |
if (env.containsKey("multi-release")) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
104 |
zipfs = new JarFileSystem(this, path, env); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
105 |
} else { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
106 |
zipfs = new ZipFileSystem(this, path, env); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
107 |
} |
28562
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
25859
diff
changeset
|
108 |
} catch (ZipException ze) { |
8386
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
109 |
String pname = path.toString(); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
110 |
if (pname.endsWith(".zip") || pname.endsWith(".jar")) |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
111 |
throw ze; |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
112 |
// assume NOT a zip/jar file |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
113 |
throw new UnsupportedOperationException(); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
114 |
} |
32306
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
28562
diff
changeset
|
115 |
if (realPath == null) { // newly created |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
28562
diff
changeset
|
116 |
realPath = path.toRealPath(); |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
28562
diff
changeset
|
117 |
} |
8386
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
118 |
filesystems.put(realPath, zipfs); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
119 |
return zipfs; |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
120 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
121 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
122 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
123 |
@Override |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
124 |
public FileSystem newFileSystem(Path path, Map<String, ?> env) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
125 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
126 |
{ |
8386
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
127 |
if (path.getFileSystem() != FileSystems.getDefault()) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
128 |
throw new UnsupportedOperationException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
129 |
} |
8386
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
130 |
ensureFile(path); |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
131 |
try { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
132 |
ZipFileSystem zipfs; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
133 |
if (env.containsKey("multi-release")) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
134 |
zipfs = new JarFileSystem(this, path, env); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
135 |
} else { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
136 |
zipfs = new ZipFileSystem(this, path, env); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
137 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
32306
diff
changeset
|
138 |
return zipfs; |
28562
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
25859
diff
changeset
|
139 |
} catch (ZipException ze) { |
8386
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
140 |
String pname = path.toString(); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
141 |
if (pname.endsWith(".zip") || pname.endsWith(".jar")) |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
142 |
throw ze; |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8165
diff
changeset
|
143 |
throw new UnsupportedOperationException(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
144 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
145 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
146 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
147 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
148 |
public Path getPath(URI uri) { |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
149 |
String spec = uri.getSchemeSpecificPart(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
150 |
int sep = spec.indexOf("!/"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
151 |
if (sep == -1) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
152 |
throw new IllegalArgumentException("URI: " |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
153 |
+ uri |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
154 |
+ " does not contain path info ex. jar:file:/c:/foo.zip!/BAR"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
155 |
return getFileSystem(uri).getPath(spec.substring(sep + 1)); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
156 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
157 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
158 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
159 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
160 |
public FileSystem getFileSystem(URI uri) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
161 |
synchronized (filesystems) { |
7189 | 162 |
ZipFileSystem zipfs = null; |
163 |
try { |
|
9025
a72fc1fc4b71
7029979: (fs) Path.toRealPath(boolean) should be toRealPath(LinkOption...)
alanb
parents:
8386
diff
changeset
|
164 |
zipfs = filesystems.get(uriToPath(uri).toRealPath()); |
7189 | 165 |
} catch (IOException x) { |
166 |
// ignore the ioe from toRealPath(), return FSNFE |
|
167 |
} |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
168 |
if (zipfs == null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
169 |
throw new FileSystemNotFoundException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
170 |
return zipfs; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
171 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
172 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
173 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
174 |
// Checks that the given file is a UnixPath |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
175 |
static final ZipPath toZipPath(Path path) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
176 |
if (path == null) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
177 |
throw new NullPointerException(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
178 |
if (!(path instanceof ZipPath)) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
179 |
throw new ProviderMismatchException(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
180 |
return (ZipPath)path; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
181 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
182 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
183 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
184 |
public void checkAccess(Path path, AccessMode... modes) throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
185 |
toZipPath(path).checkAccess(modes); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
186 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
187 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
188 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
189 |
public void copy(Path src, Path target, CopyOption... options) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
190 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
191 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
192 |
toZipPath(src).copy(toZipPath(target), options); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
193 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
194 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
195 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
196 |
public void createDirectory(Path path, FileAttribute<?>... attrs) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
197 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
198 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
199 |
toZipPath(path).createDirectory(attrs); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
200 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
201 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
202 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
203 |
public final void delete(Path path) throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
204 |
toZipPath(path).delete(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
205 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
206 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
207 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
208 |
@SuppressWarnings("unchecked") |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
209 |
public <V extends FileAttributeView> V |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
210 |
getFileAttributeView(Path path, Class<V> type, LinkOption... options) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
211 |
{ |
11841
38a39c748880
7143230: fix warnings in java.util.jar, sun.tools.jar, zipfs demo, etc.
smarks
parents:
10292
diff
changeset
|
212 |
return ZipFileAttributeView.get(toZipPath(path), type); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
213 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
214 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
215 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
216 |
public FileStore getFileStore(Path path) throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
217 |
return toZipPath(path).getFileStore(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
218 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
219 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
220 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
221 |
public boolean isHidden(Path path) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
222 |
return toZipPath(path).isHidden(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
223 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
224 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
225 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
226 |
public boolean isSameFile(Path path, Path other) throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
227 |
return toZipPath(path).isSameFile(other); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
228 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
229 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
230 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
231 |
public void move(Path src, Path target, CopyOption... options) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
232 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
233 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
234 |
toZipPath(src).move(toZipPath(target), options); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
235 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
236 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
237 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
238 |
public AsynchronousFileChannel newAsynchronousFileChannel(Path path, |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
239 |
Set<? extends OpenOption> options, |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
240 |
ExecutorService exec, |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
241 |
FileAttribute<?>... attrs) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
242 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
243 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
244 |
throw new UnsupportedOperationException(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
245 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
246 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
247 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
248 |
public SeekableByteChannel newByteChannel(Path path, |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
249 |
Set<? extends OpenOption> options, |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
250 |
FileAttribute<?>... attrs) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
251 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
252 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
253 |
return toZipPath(path).newByteChannel(options, attrs); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
254 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
255 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
256 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
257 |
public DirectoryStream<Path> newDirectoryStream( |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
258 |
Path path, Filter<? super Path> filter) throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
259 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
260 |
return toZipPath(path).newDirectoryStream(filter); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
261 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
262 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
263 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
264 |
public FileChannel newFileChannel(Path path, |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
265 |
Set<? extends OpenOption> options, |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
266 |
FileAttribute<?>... attrs) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
267 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
268 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
269 |
return toZipPath(path).newFileChannel(options, attrs); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
270 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
271 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
272 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
273 |
public InputStream newInputStream(Path path, OpenOption... options) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
274 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
275 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
276 |
return toZipPath(path).newInputStream(options); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
277 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
278 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
279 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
280 |
public OutputStream newOutputStream(Path path, OpenOption... options) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
281 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
282 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
283 |
return toZipPath(path).newOutputStream(options); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
284 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
285 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
286 |
@Override |
25798
0b2f54e47bc4
8054050: Fix stay raw and unchecked lint warnings in core libs
darcy
parents:
23925
diff
changeset
|
287 |
@SuppressWarnings("unchecked") // Cast to A |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
288 |
public <A extends BasicFileAttributes> A |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
289 |
readAttributes(Path path, Class<A> type, LinkOption... options) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
290 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
291 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
292 |
if (type == BasicFileAttributes.class || type == ZipFileAttributes.class) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
293 |
return (A)toZipPath(path).getAttributes(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
294 |
return null; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
295 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
296 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
297 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
298 |
public Map<String, Object> |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
299 |
readAttributes(Path path, String attribute, LinkOption... options) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
300 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
301 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
302 |
return toZipPath(path).readAttributes(attribute, options); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
303 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
304 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
305 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
306 |
public Path readSymbolicLink(Path link) throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
307 |
throw new UnsupportedOperationException("Not supported."); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
308 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
309 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
310 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
311 |
public void setAttribute(Path path, String attribute, |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
312 |
Object value, LinkOption... options) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
313 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
314 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
315 |
toZipPath(path).setAttribute(attribute, value, options); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
316 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
317 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
318 |
////////////////////////////////////////////////////////////// |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
319 |
void removeFileSystem(Path zfpath, ZipFileSystem zfs) throws IOException { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
320 |
synchronized (filesystems) { |
9025
a72fc1fc4b71
7029979: (fs) Path.toRealPath(boolean) should be toRealPath(LinkOption...)
alanb
parents:
8386
diff
changeset
|
321 |
zfpath = zfpath.toRealPath(); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
322 |
if (filesystems.get(zfpath) == zfs) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
323 |
filesystems.remove(zfpath); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
324 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
325 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
326 |
} |