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
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)
322 filesystems.remove(zfpath);
323 }
324 }
325 }
|
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.security.AccessController;
43 import java.security.PrivilegedActionException;
44 import java.security.PrivilegedExceptionAction;
45 import java.util.HashMap;
46 import java.util.Map;
47 import java.util.Set;
48 import java.util.concurrent.ExecutorService;
49 import java.util.zip.ZipException;
50
51 /**
52 * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal
53 */
54 public class ZipFileSystemProvider extends FileSystemProvider {
55
56 private final Map<Path, ZipFileSystem> filesystems = new HashMap<>();
57
58 public ZipFileSystemProvider() {}
59
60 @Override
61 public String getScheme() {
62 return "jar";
63 }
64
303 {
304 return toZipPath(path).readAttributes(attribute, 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 Path tempPath = zfpath;
324 try {
325 zfpath = AccessController.doPrivileged(
326 (PrivilegedExceptionAction<Path>) () -> tempPath.toRealPath(),
327 null,
328 new java.util.PropertyPermission("user.dir", "read"));
329 } catch (PrivilegedActionException e) {
330 throw (IOException) e.getException();
331 }
332 if (filesystems.get(zfpath) == zfs)
333 filesystems.remove(zfpath);
334 }
335 }
336 }
|