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 }
271 @Override
272 public InputStream newInputStream(Path path, OpenOption... options)
273 throws IOException
274 {
275 return toZipPath(path).newInputStream(options);
276 }
277
278 @Override
279 public OutputStream newOutputStream(Path path, OpenOption... options)
280 throws IOException
281 {
282 return toZipPath(path).newOutputStream(options);
283 }
284
285 @Override
286 @SuppressWarnings("unchecked") // Cast to A
287 public <A extends BasicFileAttributes> A
288 readAttributes(Path path, Class<A> type, LinkOption... options)
289 throws IOException
290 {
291 if (type == BasicFileAttributes.class || type == ZipFileAttributes.class)
292 return (A)toZipPath(path).getAttributes();
293 return null;
294 }
295
296 @Override
297 public Map<String, Object>
298 readAttributes(Path path, String attribute, LinkOption... options)
299 throws IOException
300 {
301 return toZipPath(path).readAttributes(attribute, options);
302 }
303
304 @Override
305 public Path readSymbolicLink(Path link) throws IOException {
306 throw new UnsupportedOperationException("Not supported.");
307 }
308
309 @Override
310 public void setAttribute(Path path, String attribute,
311 Object value, LinkOption... options)
312 throws IOException
313 {
314 toZipPath(path).setAttribute(attribute, value, options);
315 }
316
317 //////////////////////////////////////////////////////////////
318 void removeFileSystem(Path zfpath, ZipFileSystem zfs) throws IOException {
319 synchronized (filesystems) {
320 zfpath = zfpath.toRealPath();
321 if (filesystems.get(zfpath) == zfs)
|
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.attribute.PosixFileAttributes;
42 import java.nio.file.spi.FileSystemProvider;
43 import java.util.HashMap;
44 import java.util.Map;
45 import java.util.Set;
46 import java.util.concurrent.ExecutorService;
47 import java.util.zip.ZipException;
48
49 /**
50 * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal
51 */
52 public class ZipFileSystemProvider extends FileSystemProvider {
53
54 private final Map<Path, ZipFileSystem> filesystems = new HashMap<>();
55
56 public ZipFileSystemProvider() {}
57
58 @Override
59 public String getScheme() {
60 return "jar";
61 }
272 @Override
273 public InputStream newInputStream(Path path, OpenOption... options)
274 throws IOException
275 {
276 return toZipPath(path).newInputStream(options);
277 }
278
279 @Override
280 public OutputStream newOutputStream(Path path, OpenOption... options)
281 throws IOException
282 {
283 return toZipPath(path).newOutputStream(options);
284 }
285
286 @Override
287 @SuppressWarnings("unchecked") // Cast to A
288 public <A extends BasicFileAttributes> A
289 readAttributes(Path path, Class<A> type, LinkOption... options)
290 throws IOException
291 {
292 if (type == BasicFileAttributes.class ||
293 type == PosixFileAttributes.class ||
294 type == ZipFileAttributes.class)
295 return (A)toZipPath(path).getAttributes();
296 return null;
297 }
298
299 @Override
300 public Map<String, Object>
301 readAttributes(Path path, String attributes, LinkOption... options)
302 throws IOException
303 {
304 return toZipPath(path).readAttributes(attributes, options);
305 }
306
307 @Override
308 public Path readSymbolicLink(Path link) throws IOException {
309 throw new UnsupportedOperationException("Not supported.");
310 }
311
312 @Override
313 public void setAttribute(Path path, String attribute,
314 Object value, LinkOption... options)
315 throws IOException
316 {
317 toZipPath(path).setAttribute(attribute, value, options);
318 }
319
320 //////////////////////////////////////////////////////////////
321 void removeFileSystem(Path zfpath, ZipFileSystem zfs) throws IOException {
322 synchronized (filesystems) {
323 zfpath = zfpath.toRealPath();
324 if (filesystems.get(zfpath) == zfs)
|