src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java
author redestad
Wed, 24 Apr 2019 15:37:55 +0200
changeset 54608 c604234be658
parent 53516 cd310319fead
child 54920 6a6935abebe8
permissions -rw-r--r--
8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel Reviewed-by: lancea, clanger, 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 {
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    55
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    56
    private final Map<Path, ZipFileSystem> filesystems = new HashMap<>();
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    57
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    58
    public ZipFileSystemProvider() {}
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    59
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    60
    @Override
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    61
    public String getScheme() {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    62
        return "jar";
6699
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
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    65
    protected Path uriToPath(URI uri) {
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    66
        String scheme = uri.getScheme();
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    67
        if ((scheme == null) || !scheme.equalsIgnoreCase(getScheme())) {
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    68
            throw new IllegalArgumentException("URI scheme is not '" + getScheme() + "'");
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
        try {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    71
            // 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
    72
            String spec = uri.getRawSchemeSpecificPart();
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    73
            int sep = spec.indexOf("!/");
32306
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
    74
            if (sep != -1) {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    75
                spec = spec.substring(0, sep);
32306
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
    76
            }
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    77
            return Paths.get(new URI(spec)).toAbsolutePath();
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    78
        } catch (URISyntaxException e) {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
    79
            throw new IllegalArgumentException(e.getMessage(), e);
6699
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
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    82
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    83
    private boolean ensureFile(Path path) {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    84
        try {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    85
            BasicFileAttributes attrs =
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    86
                Files.readAttributes(path, BasicFileAttributes.class);
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    87
            if (!attrs.isRegularFile())
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    88
                throw new UnsupportedOperationException();
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    89
            return true;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    90
        } catch (IOException ioe) {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    91
            return false;
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
    }
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    94
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    95
    @Override
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    96
    public FileSystem newFileSystem(URI uri, Map<String, ?> env)
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    97
        throws IOException
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    98
    {
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
    99
        Path path = uriToPath(uri);
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   100
        synchronized(filesystems) {
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   101
            Path realPath = null;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   102
            if (ensureFile(path)) {
9025
a72fc1fc4b71 7029979: (fs) Path.toRealPath(boolean) should be toRealPath(LinkOption...)
alanb
parents: 8386
diff changeset
   103
                realPath = path.toRealPath();
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   104
                if (filesystems.containsKey(realPath))
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   105
                    throw new FileSystemAlreadyExistsException();
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   106
            }
54608
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   107
            ZipFileSystem zipfs;
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   108
            try {
34835
ee52702b8d1b 8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents: 32306
diff changeset
   109
                if (env.containsKey("multi-release")) {
ee52702b8d1b 8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents: 32306
diff changeset
   110
                    zipfs = new JarFileSystem(this, path, env);
ee52702b8d1b 8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents: 32306
diff changeset
   111
                } else {
ee52702b8d1b 8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents: 32306
diff changeset
   112
                    zipfs = new ZipFileSystem(this, path, env);
ee52702b8d1b 8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents: 32306
diff changeset
   113
                }
28562
a3e34b364d38 8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents: 25859
diff changeset
   114
            } catch (ZipException ze) {
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   115
                String pname = path.toString();
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   116
                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
   117
                    throw ze;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   118
                // assume NOT a zip/jar file
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   119
                throw new UnsupportedOperationException();
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   120
            }
32306
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
   121
            if (realPath == null) {  // newly created
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
   122
                realPath = path.toRealPath();
d08fa5944065 8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents: 28562
diff changeset
   123
            }
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   124
            filesystems.put(realPath, zipfs);
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   125
            return zipfs;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   126
        }
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   127
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   128
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   129
    @Override
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   130
    public FileSystem newFileSystem(Path path, Map<String, ?> env)
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   131
        throws IOException
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   132
    {
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   133
        ensureFile(path);
54608
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   134
        try {
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   135
            ZipFileSystem zipfs;
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   136
            if (env.containsKey("multi-release")) {
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   137
                zipfs = new JarFileSystem(this, path, env);
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   138
            } else {
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   139
                zipfs = new ZipFileSystem(this, path, env);
c604234be658 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
redestad
parents: 53516
diff changeset
   140
            }
34835
ee52702b8d1b 8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents: 32306
diff changeset
   141
            return zipfs;
28562
a3e34b364d38 8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents: 25859
diff changeset
   142
        } catch (ZipException ze) {
8386
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   143
            String pname = path.toString();
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   144
            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
   145
                throw ze;
4a1a689a32e0 7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents: 8165
diff changeset
   146
            throw new UnsupportedOperationException();
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   147
        }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   148
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   149
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   150
    @Override
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   151
    public Path getPath(URI uri) {
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
   152
        String spec = uri.getSchemeSpecificPart();
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
   153
        int sep = spec.indexOf("!/");
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
   154
        if (sep == -1)
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   155
            throw new IllegalArgumentException("URI: "
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   156
                + uri
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
   157
                + " 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
   158
        return getFileSystem(uri).getPath(spec.substring(sep + 1));
6699
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
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   161
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   162
    @Override
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   163
    public FileSystem getFileSystem(URI uri) {
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   164
        synchronized (filesystems) {
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   165
            ZipFileSystem zipfs = null;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   166
            try {
9025
a72fc1fc4b71 7029979: (fs) Path.toRealPath(boolean) should be toRealPath(LinkOption...)
alanb
parents: 8386
diff changeset
   167
                zipfs = filesystems.get(uriToPath(uri).toRealPath());
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   168
            } catch (IOException x) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   169
                // ignore the ioe from toRealPath(), return FSNFE
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   170
            }
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   171
            if (zipfs == null)
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   172
                throw new FileSystemNotFoundException();
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   173
            return zipfs;
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   174
        }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   175
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   176
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   177
    // Checks that the given file is a UnixPath
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   178
    static final ZipPath toZipPath(Path path) {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   179
        if (path == null)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   180
            throw new NullPointerException();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   181
        if (!(path instanceof ZipPath))
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   182
            throw new ProviderMismatchException();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   183
        return (ZipPath)path;
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   184
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   187
    public void checkAccess(Path path, AccessMode... modes) throws IOException {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   188
        toZipPath(path).checkAccess(modes);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   189
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   190
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   191
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   192
    public void copy(Path src, Path target, CopyOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   193
        throws IOException
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
        toZipPath(src).copy(toZipPath(target), options);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   196
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   197
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   198
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   199
    public void createDirectory(Path path, FileAttribute<?>... attrs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   200
        throws IOException
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
        toZipPath(path).createDirectory(attrs);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   203
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   206
    public final void delete(Path path) throws IOException {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   207
        toZipPath(path).delete();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   208
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   211
    public <V extends FileAttributeView> V
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   212
        getFileAttributeView(Path path, Class<V> type, LinkOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   213
    {
11841
38a39c748880 7143230: fix warnings in java.util.jar, sun.tools.jar, zipfs demo, etc.
smarks
parents: 10292
diff changeset
   214
        return ZipFileAttributeView.get(toZipPath(path), type);
8165
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   217
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   218
    public FileStore getFileStore(Path path) throws IOException {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   219
        return toZipPath(path).getFileStore();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   220
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   223
    public boolean isHidden(Path path) {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   224
        return toZipPath(path).isHidden();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   225
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   226
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   227
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   228
    public boolean isSameFile(Path path, Path other) throws IOException {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   229
        return toZipPath(path).isSameFile(other);
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 void move(Path src, Path target, CopyOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   234
        throws IOException
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
        toZipPath(src).move(toZipPath(target), options);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   239
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   240
    public AsynchronousFileChannel newAsynchronousFileChannel(Path path,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   241
            Set<? extends OpenOption> options,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   242
            ExecutorService exec,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   243
            FileAttribute<?>... attrs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   244
            throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   245
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   246
        throw new UnsupportedOperationException();
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   249
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   250
    public SeekableByteChannel newByteChannel(Path path,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   251
                                              Set<? extends OpenOption> options,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   252
                                              FileAttribute<?>... attrs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   253
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   254
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   255
        return toZipPath(path).newByteChannel(options, attrs);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   258
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   259
    public DirectoryStream<Path> newDirectoryStream(
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   260
        Path path, Filter<? super Path> filter) throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   261
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   262
        return toZipPath(path).newDirectoryStream(filter);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   265
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   266
    public FileChannel newFileChannel(Path path,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   267
                                      Set<? extends OpenOption> options,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   268
                                      FileAttribute<?>... attrs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   269
        throws IOException
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
        return toZipPath(path).newFileChannel(options, attrs);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   272
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   275
    public InputStream newInputStream(Path path, OpenOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   276
        throws IOException
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
        return toZipPath(path).newInputStream(options);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   279
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   282
    public OutputStream newOutputStream(Path path, OpenOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   283
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   284
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   285
        return toZipPath(path).newOutputStream(options);
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
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   288
    @Override
25798
0b2f54e47bc4 8054050: Fix stay raw and unchecked lint warnings in core libs
darcy
parents: 23925
diff changeset
   289
    @SuppressWarnings("unchecked") // Cast to A
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   290
    public <A extends BasicFileAttributes> A
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   291
        readAttributes(Path path, Class<A> type, LinkOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   292
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   293
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   294
        if (type == BasicFileAttributes.class || type == ZipFileAttributes.class)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   295
            return (A)toZipPath(path).getAttributes();
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   296
        return null;
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   297
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   300
    public Map<String, Object>
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   301
        readAttributes(Path path, String attribute, LinkOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   302
        throws IOException
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
        return toZipPath(path).readAttributes(attribute, options);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   305
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   306
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   307
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   308
    public Path readSymbolicLink(Path link) throws IOException {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   309
        throw new UnsupportedOperationException("Not supported.");
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   310
    }
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
    @Override
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   313
    public void setAttribute(Path path, String attribute,
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   314
                             Object value, LinkOption... options)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   315
        throws IOException
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   316
    {
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   317
        toZipPath(path).setAttribute(attribute, value, options);
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   318
    }
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   319
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   320
    //////////////////////////////////////////////////////////////
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   321
    void removeFileSystem(Path zfpath, ZipFileSystem zfs) throws IOException {
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   322
        synchronized (filesystems) {
53516
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   323
            Path tempPath = zfpath;
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   324
            PrivilegedExceptionAction<Path> action = tempPath::toRealPath;
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   325
            try {
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   326
                zfpath = AccessController.doPrivileged(action);
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   327
            } catch (PrivilegedActionException e) {
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   328
                throw (IOException) e.getException();
cd310319fead 8210469: Missing doPriviledged block and permission for jdk.zipfs module
lancea
parents: 53043
diff changeset
   329
            }
8165
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   330
            if (filesystems.get(zfpath) == zfs)
b67d8b1f4e46 7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents: 7531
diff changeset
   331
                filesystems.remove(zfpath);
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   332
        }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   333
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   334
}