src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java
author pconcannon
Fri, 25 Oct 2019 12:05:56 +0100
changeset 58803 1bd307ea5497
parent 58467 72ef2c0faf47
child 59216 47c879f478d2
permissions -rw-r--r--
8231570: (dc) Clarify implicit bind behavior of DatagramChannel Summary: Update to DatagramChannel spec to make it clear that SecurityException can be thrown in connect send and receive methods Reviewed-by: alanb, chegar, dfuchs
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 {
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    55
58467
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
    56
    // Property used to specify the entry version to use for a multi-release JAR
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
    57
    static final String PROPERTY_RELEASE_VERSION = "releaseVersion";
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
    58
    // Original property used to specify the entry version to use for a
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
    59
    // multi-release JAR which is kept for backwards compatibility.
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
    60
    static final String PROPERTY_MULTI_RELEASE = "multi-release";
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    61
    private final Map<Path, ZipFileSystem> filesystems = new HashMap<>();
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
    public ZipFileSystemProvider() {}
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    64
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    65
    @Override
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    66
    public String getScheme() {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    67
        return "jar";
6699
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
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    70
    protected Path uriToPath(URI uri) {
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    71
        String scheme = uri.getScheme();
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    72
        if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    73
            throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
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
        try {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    76
            // 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
    77
            String spec = uri.getRawSchemeSpecificPart();
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    78
            int sep = spec.indexOf("!/");
32306
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
    79
            if (sep != -1) {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    80
                spec = spec.substring(0, sep);
32306
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
    81
            }
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    82
            return Paths.get(new URI(spec)).toAbsolutePath();
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    83
        } catch (URISyntaxException e) {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    84
            throw new IllegalArgumentException(e.getMessage(), e);
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    85
        }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    86
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    87
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    88
    private boolean ensureFile(Path path) {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    89
        try {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    90
            BasicFileAttributes attrs =
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    91
                Files.readAttributes(path, BasicFileAttributes.class);
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    92
            if (!attrs.isRegularFile())
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    93
                throw new UnsupportedOperationException();
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    94
            return true;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    95
        } catch (IOException ioe) {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    96
            return false;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    97
        }
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    98
    }
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    99
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   100
    @Override
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   101
    public FileSystem newFileSystem(URI uri, Map<String, ?> env)
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   102
        throws IOException
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   103
    {
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   104
        Path path = uriToPath(uri);
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   105
        synchronized(filesystems) {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   106
            Path realPath = null;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   107
            if (ensureFile(path)) {
9025
a72fc1fc4b71 7029979: (fs) Path.toRealPath(boolean) should be toRealPath(LinkOption...)
alanb
parents: 8386
diff changeset
   108
                realPath = path.toRealPath();
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   109
                if (filesystems.containsKey(realPath))
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   110
                    throw new FileSystemAlreadyExistsException();
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   111
            }
58467
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   112
            ZipFileSystem zipfs = getZipFileSystem(path, env);
32306
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
   113
            if (realPath == null) {  // newly created
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
   114
                realPath = path.toRealPath();
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
   115
            }
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   116
            filesystems.put(realPath, zipfs);
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   117
            return zipfs;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   118
        }
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   119
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   120
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   121
    @Override
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   122
    public FileSystem newFileSystem(Path path, Map<String, ?> env)
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   123
        throws IOException
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   124
    {
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   125
        ensureFile(path);
58467
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   126
        return getZipFileSystem(path, env);
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   127
    }
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   128
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   129
    private ZipFileSystem getZipFileSystem(Path path, Map<String, ?> env) throws IOException {
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   130
        ZipFileSystem zipfs;
54608
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   131
        try {
58467
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   132
            if (env.containsKey(PROPERTY_RELEASE_VERSION) ||
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   133
                    env.containsKey(PROPERTY_MULTI_RELEASE)) {
54608
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   134
                zipfs = new JarFileSystem(this, path, env);
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   135
            } else {
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   136
                zipfs = new ZipFileSystem(this, path, env);
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   137
            }
28562
a3e34b364d38 8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents: 25859
diff changeset
   138
        } catch (ZipException ze) {
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   139
            String pname = path.toString();
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   140
            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
   141
                throw ze;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   142
            throw new UnsupportedOperationException();
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   143
        }
58467
72ef2c0faf47 8231093: Document the ZIP FS properties noCompression and releaseVersion
lancea
parents: 54920
diff changeset
   144
        return zipfs;
6699
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
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   162
            ZipFileSystem zipfs = null;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   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
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   165
            } catch (IOException x) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   166
                // ignore the ioe from toRealPath(), return FSNFE
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   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
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   175
    private static ZipPath toZipPath(Path path) {
8165
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
    public <V extends FileAttributeView> V
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   209
        getFileAttributeView(Path path, Class<V> type, LinkOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   210
    {
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   211
        return toZipPath(path).getFileAttributeView(type);
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   212
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   215
    public FileStore getFileStore(Path path) throws IOException {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   216
        return toZipPath(path).getFileStore();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   217
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   220
    public boolean isHidden(Path path) {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   221
        return toZipPath(path).isHidden();
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   224
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   225
    public boolean isSameFile(Path path, Path other) throws IOException {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   226
        return toZipPath(path).isSameFile(other);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   227
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   230
    public void move(Path src, Path target, CopyOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   231
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   232
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   233
        toZipPath(src).move(toZipPath(target), options);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   234
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   237
    public AsynchronousFileChannel newAsynchronousFileChannel(Path path,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   238
            Set<? extends OpenOption> options,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   239
            ExecutorService exec,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   240
            FileAttribute<?>... attrs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   241
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   242
        throw new UnsupportedOperationException();
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   245
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   246
    public SeekableByteChannel newByteChannel(Path path,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   247
                                              Set<? extends OpenOption> options,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   248
                                              FileAttribute<?>... attrs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   249
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   250
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   251
        return toZipPath(path).newByteChannel(options, attrs);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   254
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   255
    public DirectoryStream<Path> newDirectoryStream(
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   256
        Path path, Filter<? super Path> filter) throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   257
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   258
        return toZipPath(path).newDirectoryStream(filter);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   261
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   262
    public FileChannel newFileChannel(Path path,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   263
                                      Set<? extends OpenOption> options,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   264
                                      FileAttribute<?>... attrs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   265
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   266
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   267
        return toZipPath(path).newFileChannel(options, attrs);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   270
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   271
    public InputStream newInputStream(Path path, OpenOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   272
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   273
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   274
        return toZipPath(path).newInputStream(options);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   277
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   278
    public OutputStream newOutputStream(Path path, OpenOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   279
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   280
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   281
        return toZipPath(path).newOutputStream(options);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   284
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   285
    public <A extends BasicFileAttributes> A
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   286
        readAttributes(Path path, Class<A> type, LinkOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   287
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   288
    {
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   289
        return toZipPath(path).readAttributes(type);
8165
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 Map<String, Object>
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   294
        readAttributes(Path path, String attributes, LinkOption... options)
8165
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
    {
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   297
        return toZipPath(path).readAttributes(attributes, options);
8165
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
    @Override
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 54608
diff changeset
   301
    public Path readSymbolicLink(Path link) {
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   302
        throw new UnsupportedOperationException("Not supported.");
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 void setAttribute(Path path, String attribute,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   307
                             Object value, LinkOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   308
        throws IOException
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
        toZipPath(path).setAttribute(attribute, value, options);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   311
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   312
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   313
    //////////////////////////////////////////////////////////////
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   314
    void removeFileSystem(Path zfpath, ZipFileSystem zfs) throws IOException {
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   315
        synchronized (filesystems) {
53516
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   316
            Path tempPath = zfpath;
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   317
            PrivilegedExceptionAction<Path> action = tempPath::toRealPath;
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   318
            try {
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   319
                zfpath = AccessController.doPrivileged(action);
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   320
            } catch (PrivilegedActionException e) {
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   321
                throw (IOException) e.getException();
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   322
            }
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   323
            if (filesystems.get(zfpath) == zfs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   324
                filesystems.remove(zfpath);
6699
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
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   327
}