src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java
author clanger
Fri, 22 Nov 2019 09:25:09 +0100
changeset 59216 47c879f478d2
parent 58467 72ef2c0faf47
permissions -rw-r--r--
8234089: (zipfs) Remove classes JarFileSystemProvider and JarFileSystem Reviewed-by: lancea, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
     1
/*
54608
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
     2
 * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
23925
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
53043
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    28
import java.io.IOException;
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    29
import java.io.InputStream;
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    30
import java.io.OutputStream;
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    31
import java.net.URI;
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    32
import java.net.URISyntaxException;
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    33
import java.nio.channels.AsynchronousFileChannel;
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    34
import java.nio.channels.FileChannel;
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    35
import java.nio.channels.SeekableByteChannel;
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
    36
import java.nio.file.*;
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
    37
import java.nio.file.DirectoryStream.Filter;
53043
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    38
import java.nio.file.attribute.BasicFileAttributes;
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    39
import java.nio.file.attribute.FileAttribute;
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    40
import java.nio.file.attribute.FileAttributeView;
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    41
import java.nio.file.spi.FileSystemProvider;
53516
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
    42
import java.security.AccessController;
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
    43
import java.security.PrivilegedActionException;
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
    44
import java.security.PrivilegedExceptionAction;
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    45
import java.util.HashMap;
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    46
import java.util.Map;
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    47
import java.util.Set;
53043
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    48
import java.util.concurrent.ExecutorService;
28562
a3e34b364d38 8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents: 25859
diff changeset
    49
import java.util.zip.ZipException;
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    50
53043
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    51
/**
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 51787
diff changeset
    52
 * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal
6699
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
public class ZipFileSystemProvider extends FileSystemProvider {
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    55
    private final Map<Path, ZipFileSystem> filesystems = new HashMap<>();
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    56
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    57
    public ZipFileSystemProvider() {}
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
    @Override
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    60
    public String getScheme() {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    61
        return "jar";
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    62
    }
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
    protected Path uriToPath(URI uri) {
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    65
        String scheme = uri.getScheme();
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    66
        if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    67
            throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    68
        }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    69
        try {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    70
            // 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
    71
            String spec = uri.getRawSchemeSpecificPart();
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    72
            int sep = spec.indexOf("!/");
32306
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
    73
            if (sep != -1) {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    74
                spec = spec.substring(0, sep);
32306
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
    75
            }
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    76
            return Paths.get(new URI(spec)).toAbsolutePath();
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    77
        } catch (URISyntaxException e) {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    78
            throw new IllegalArgumentException(e.getMessage(), e);
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    79
        }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    80
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    81
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    82
    private boolean ensureFile(Path path) {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    83
        try {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    84
            BasicFileAttributes attrs =
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    85
                Files.readAttributes(path, BasicFileAttributes.class);
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    86
            if (!attrs.isRegularFile())
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    87
                throw new UnsupportedOperationException();
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    88
            return true;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    89
        } catch (IOException ioe) {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    90
            return false;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    91
        }
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    92
    }
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    93
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    94
    @Override
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    95
    public FileSystem newFileSystem(URI uri, Map<String, ?> env)
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    96
        throws IOException
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    97
    {
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    98
        Path path = uriToPath(uri);
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    99
        synchronized(filesystems) {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   100
            Path realPath = null;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   101
            if (ensureFile(path)) {
9025
a72fc1fc4b71 7029979: (fs) Path.toRealPath(boolean) should be toRealPath(LinkOption...)
alanb
parents: 8386
diff changeset
   102
                realPath = path.toRealPath();
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   103
                if (filesystems.containsKey(realPath))
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   104
                    throw new FileSystemAlreadyExistsException();
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   105
            }
58467
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   106
            ZipFileSystem zipfs = getZipFileSystem(path, env);
32306
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
   107
            if (realPath == null) {  // newly created
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
   108
                realPath = path.toRealPath();
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
   109
            }
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   110
            filesystems.put(realPath, zipfs);
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   111
            return zipfs;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   112
        }
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   113
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   114
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   115
    @Override
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   116
    public FileSystem newFileSystem(Path path, Map<String, ?> env)
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   117
        throws IOException
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   118
    {
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   119
        ensureFile(path);
58467
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   120
        return getZipFileSystem(path, env);
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   121
    }
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   122
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   123
    private ZipFileSystem getZipFileSystem(Path path, Map<String, ?> env) throws IOException {
54608
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   124
        try {
59216
47c879f478d2 8234089: (zipfs) Remove classes JarFileSystemProvider and JarFileSystem
clanger
parents: 58467
diff changeset
   125
            return new ZipFileSystem(this, path, env);
28562
a3e34b364d38 8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents: 25859
diff changeset
   126
        } catch (ZipException ze) {
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   127
            String pname = path.toString();
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   128
            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
   129
                throw ze;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   130
            throw new UnsupportedOperationException();
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   131
        }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   132
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   133
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   134
    @Override
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   135
    public Path getPath(URI uri) {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
   136
        String spec = uri.getSchemeSpecificPart();
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
   137
        int sep = spec.indexOf("!/");
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
   138
        if (sep == -1)
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   139
            throw new IllegalArgumentException("URI: "
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   140
                + uri
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
   141
                + " 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
   142
        return getFileSystem(uri).getPath(spec.substring(sep + 1));
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   143
    }
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
    @Override
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   147
    public FileSystem getFileSystem(URI uri) {
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   148
        synchronized (filesystems) {
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   149
            ZipFileSystem zipfs = null;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   150
            try {
9025
a72fc1fc4b71 7029979: (fs) Path.toRealPath(boolean) should be toRealPath(LinkOption...)
alanb
parents: 8386
diff changeset
   151
                zipfs = filesystems.get(uriToPath(uri).toRealPath());
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   152
            } catch (IOException x) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   153
                // ignore the ioe from toRealPath(), return FSNFE
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   154
            }
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   155
            if (zipfs == null)
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   156
                throw new FileSystemNotFoundException();
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   157
            return zipfs;
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
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   160
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   161
    // Checks that the given file is a UnixPath
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   162
    private static ZipPath toZipPath(Path path) {
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   163
        if (path == null)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   164
            throw new NullPointerException();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   165
        if (!(path instanceof ZipPath))
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   166
            throw new ProviderMismatchException();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   167
        return (ZipPath)path;
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   168
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   169
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   170
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   171
    public void checkAccess(Path path, AccessMode... modes) throws IOException {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   172
        toZipPath(path).checkAccess(modes);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   173
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   174
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   175
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   176
    public void copy(Path src, Path target, CopyOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   177
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   178
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   179
        toZipPath(src).copy(toZipPath(target), options);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   180
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   183
    public void createDirectory(Path path, FileAttribute<?>... attrs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   184
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   185
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   186
        toZipPath(path).createDirectory(attrs);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   189
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   190
    public final void delete(Path path) throws IOException {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   191
        toZipPath(path).delete();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   192
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   195
    public <V extends FileAttributeView> V
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   196
        getFileAttributeView(Path path, Class<V> type, LinkOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   197
    {
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   198
        return toZipPath(path).getFileAttributeView(type);
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   199
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   202
    public FileStore getFileStore(Path path) throws IOException {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   203
        return toZipPath(path).getFileStore();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   204
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   207
    public boolean isHidden(Path path) {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   208
        return toZipPath(path).isHidden();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   209
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   210
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   211
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   212
    public boolean isSameFile(Path path, Path other) throws IOException {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   213
        return toZipPath(path).isSameFile(other);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   216
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   217
    public void move(Path src, Path target, CopyOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   218
        throws IOException
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
        toZipPath(src).move(toZipPath(target), options);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   221
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   222
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   223
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   224
    public AsynchronousFileChannel newAsynchronousFileChannel(Path path,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   225
            Set<? extends OpenOption> options,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   226
            ExecutorService exec,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   227
            FileAttribute<?>... attrs)
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
        throw new UnsupportedOperationException();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   230
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   231
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   232
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   233
    public SeekableByteChannel newByteChannel(Path path,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   234
                                              Set<? extends OpenOption> options,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   235
                                              FileAttribute<?>... attrs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   236
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   237
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   238
        return toZipPath(path).newByteChannel(options, attrs);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   239
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   240
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   241
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   242
    public DirectoryStream<Path> newDirectoryStream(
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   243
        Path path, Filter<? super Path> filter) throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   244
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   245
        return toZipPath(path).newDirectoryStream(filter);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   248
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   249
    public FileChannel newFileChannel(Path path,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   250
                                      Set<? extends OpenOption> options,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   251
                                      FileAttribute<?>... attrs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   252
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   253
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   254
        return toZipPath(path).newFileChannel(options, attrs);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   257
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   258
    public InputStream newInputStream(Path path, OpenOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   259
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   260
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   261
        return toZipPath(path).newInputStream(options);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   264
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   265
    public OutputStream newOutputStream(Path path, OpenOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   266
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   267
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   268
        return toZipPath(path).newOutputStream(options);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   269
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   272
    public <A extends BasicFileAttributes> A
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   273
        readAttributes(Path path, Class<A> type, LinkOption... 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
    {
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   276
        return toZipPath(path).readAttributes(type);
8165
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 Map<String, Object>
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   281
        readAttributes(Path path, String attributes, LinkOption... options)
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   282
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   283
    {
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   284
        return toZipPath(path).readAttributes(attributes, options);
8165
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   287
    @Override
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   288
    public Path readSymbolicLink(Path link) {
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   289
        throw new UnsupportedOperationException("Not supported.");
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   290
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   293
    public void setAttribute(Path path, String attribute,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   294
                             Object value, LinkOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   295
        throws IOException
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
        toZipPath(path).setAttribute(attribute, value, options);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   298
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   299
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   300
    //////////////////////////////////////////////////////////////
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   301
    void removeFileSystem(Path zfpath, ZipFileSystem zfs) throws IOException {
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   302
        synchronized (filesystems) {
53516
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   303
            Path tempPath = zfpath;
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   304
            PrivilegedExceptionAction<Path> action = tempPath::toRealPath;
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   305
            try {
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   306
                zfpath = AccessController.doPrivileged(action);
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   307
            } catch (PrivilegedActionException e) {
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   308
                throw (IOException) e.getException();
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   309
            }
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   310
            if (filesystems.get(zfpath) == zfs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   311
                filesystems.remove(zfpath);
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   312
        }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   313
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   314
}