8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nio.zipfs;
27
28 import java.io.*;
29 import java.nio.channels.*;
30 import java.nio.file.*;
31 import java.nio.file.DirectoryStream.Filter;
32 import java.nio.file.attribute.*;
33 import java.nio.file.spi.FileSystemProvider;
34 import java.net.URI;
35 import java.net.URISyntaxException;
36 import java.util.HashMap;
37 import java.util.Map;
38 import java.util.Set;
39 import java.util.zip.ZipException;
40 import java.util.concurrent.ExecutorService;
41
42 /*
43 *
44 * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal
45 */
46
47 public class ZipFileSystemProvider extends FileSystemProvider {
48
49
50 private final Map<Path, ZipFileSystem> filesystems = new HashMap<>();
51
52 public ZipFileSystemProvider() {}
53
54 @Override
55 public String getScheme() {
56 return "jar";
57 }
58
59 protected Path uriToPath(URI uri) {
60 String scheme = uri.getScheme();
61 if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
62 throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
63 }
64 try {
65 // only support legacy JAR URL syntax jar:{uri}!/{entry} for now
66 String spec = uri.getRawSchemeSpecificPart();
67 int sep = spec.indexOf("!/");
68 if (sep != -1) {
69 spec = spec.substring(0, sep);
185 @Override
186 public void copy(Path src, Path target, CopyOption... options)
187 throws IOException
188 {
189 toZipPath(src).copy(toZipPath(target), options);
190 }
191
192 @Override
193 public void createDirectory(Path path, FileAttribute<?>... attrs)
194 throws IOException
195 {
196 toZipPath(path).createDirectory(attrs);
197 }
198
199 @Override
200 public final void delete(Path path) throws IOException {
201 toZipPath(path).delete();
202 }
203
204 @Override
205 @SuppressWarnings("unchecked")
206 public <V extends FileAttributeView> V
207 getFileAttributeView(Path path, Class<V> type, LinkOption... options)
208 {
209 return ZipFileAttributeView.get(toZipPath(path), type);
210 }
211
212 @Override
213 public FileStore getFileStore(Path path) throws IOException {
214 return toZipPath(path).getFileStore();
215 }
216
217 @Override
218 public boolean isHidden(Path path) {
219 return toZipPath(path).isHidden();
220 }
221
222 @Override
223 public boolean isSameFile(Path path, Path other) throws IOException {
224 return toZipPath(path).isSameFile(other);
225 }
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nio.zipfs;
27
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.OutputStream;
31 import java.net.URI;
32 import java.net.URISyntaxException;
33 import java.nio.channels.AsynchronousFileChannel;
34 import java.nio.channels.FileChannel;
35 import java.nio.channels.SeekableByteChannel;
36 import java.nio.file.*;
37 import java.nio.file.DirectoryStream.Filter;
38 import java.nio.file.attribute.BasicFileAttributes;
39 import java.nio.file.attribute.FileAttribute;
40 import java.nio.file.attribute.FileAttributeView;
41 import java.nio.file.spi.FileSystemProvider;
42 import java.util.HashMap;
43 import java.util.Map;
44 import java.util.Set;
45 import java.util.concurrent.ExecutorService;
46 import java.util.zip.ZipException;
47
48 /**
49 * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal
50 */
51 public class ZipFileSystemProvider extends FileSystemProvider {
52
53 private final Map<Path, ZipFileSystem> filesystems = new HashMap<>();
54
55 public ZipFileSystemProvider() {}
56
57 @Override
58 public String getScheme() {
59 return "jar";
60 }
61
62 protected Path uriToPath(URI uri) {
63 String scheme = uri.getScheme();
64 if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
65 throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
66 }
67 try {
68 // only support legacy JAR URL syntax jar:{uri}!/{entry} for now
69 String spec = uri.getRawSchemeSpecificPart();
70 int sep = spec.indexOf("!/");
71 if (sep != -1) {
72 spec = spec.substring(0, sep);
188 @Override
189 public void copy(Path src, Path target, CopyOption... options)
190 throws IOException
191 {
192 toZipPath(src).copy(toZipPath(target), options);
193 }
194
195 @Override
196 public void createDirectory(Path path, FileAttribute<?>... attrs)
197 throws IOException
198 {
199 toZipPath(path).createDirectory(attrs);
200 }
201
202 @Override
203 public final void delete(Path path) throws IOException {
204 toZipPath(path).delete();
205 }
206
207 @Override
208 public <V extends FileAttributeView> V
209 getFileAttributeView(Path path, Class<V> type, LinkOption... options)
210 {
211 return ZipFileAttributeView.get(toZipPath(path), type);
212 }
213
214 @Override
215 public FileStore getFileStore(Path path) throws IOException {
216 return toZipPath(path).getFileStore();
217 }
218
219 @Override
220 public boolean isHidden(Path path) {
221 return toZipPath(path).isHidden();
222 }
223
224 @Override
225 public boolean isSameFile(Path path, Path other) throws IOException {
226 return toZipPath(path).isSameFile(other);
227 }
|