1 /*
   2  * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /**
  27  * Provides the implementation of the Zip file system provider.
  28  * The Zip file system provider treats the contents of a Zip or JAR file as a file system.
  29  * <p>
  30  *
  31  * <h3>Accessing a Zip File System</h3>
  32  *
  33  * The {@linkplain java.nio.file.FileSystems FileSystems} {@code newFileSystem}
  34  * static factory methods can be used to:
  35  * <ul>
  36  *     <li>Create a Zip file system</li>
  37  *     <li>Open an existing file as a Zip file system</li>
  38  * </ul>
  39  *
  40  * <h3>URI Scheme Used to Identify the Zip File System</h3>
  41  *
  42  * The URI {@link java.net.URI#getScheme scheme} that identifies the ZIP file system is {@code jar}.
  43  *
  44  * <h3>Posix Support</h3>
  45  *
  46  * File systems created by the Zip file system provider have a built in support
  47  * for POSIX permissions. It is possible to query a
  48  * {@link java.nio.file.Path Path} object from a Zip file system for the
  49  * attribute {@code storedPermissions}. The value of the attribute
  50  * will be of type
  51  * {@link java.util.Set}&lt;{@link java.nio.file.attribute.PosixFilePermission}&gt;.
  52  * As POSIX permission information is optional in Zip files, the attribute value
  53  * will be {@code null} in case no permission information exists for a Zip entry.<br>
  54  *
  55  * For extended POSIX support, allowing to use
  56  * {@link java.nio.file.attribute.PosixFileAttributeView} and taking advantage
  57  * of {@link java.nio.file.Files#setPosixFilePermissions Files::setPosixFilePermissions}
  58  * or {@link java.nio.file.Files#getPosixFilePermissions Files::getPosixFilePermissions},
  59  * it is possible to create a Zip file system with the property {@code posix}
  60  * set to {@code true}.
  61  * In that case, certain defaults apply. The owner of a file will be set to a
  62  * {@link java.nio.file.attribute.UserPrincipal} with its name set to the value of
  63  * {@code System.getProperty("user.name")}. The group will be a
  64  * {@link java.nio.file.attribute.GroupPrincipal} with the name "{@code <zipfs_default>}".
  65  * The default {@link java.util.Set} of permissions for cases when no permission data
  66  * is associated with a Zip file entry, will contain
  67  * {@link java.nio.file.attribute.PosixFilePermission#OWNER_READ OWNER_READ},
  68  * {@link java.nio.file.attribute.PosixFilePermission#OWNER_WRITE OWNER_WRITE} and
  69  * {@link java.nio.file.attribute.PosixFilePermission#GROUP_READ GROUP_READ}.
  70  * It is possible to override the defaults using properties as specified below.
  71  *
  72  * <h3>Zip File System Properties</h3>
  73  *
  74  * The following properties may be specified when creating a Zip
  75  * file system:
  76  * <p>
  77  * <table class="striped">
  78  * <caption style="display:none">
  79  *     Configurable properties that may be specified when creating
  80  *     a new Zip file system
  81  * </caption>
  82  * <thead>
  83  * <tr>
  84  * <th scope="col">Property Name</th>
  85  * <th scope="col">Data Type</th>
  86  * <th scope="col">Default Value</th>
  87  * <th scope="col">Description</th>
  88  * </tr>
  89  * </thead>
  90  *
  91  * <tbody>
  92  * <tr>
  93  *   <td scope="row">create</td>
  94  *   <td>java.lang.String</td>
  95  *   <td>false</td>
  96  *   <td>
  97  *       If the value is {@code true}, the Zip file system provider
  98  *       creates a new Zip or JAR file if it does not exist.
  99  *   </td>
 100  * </tr>
 101  * <tr>
 102  *   <td scope="row">encoding</td>
 103  *   <td>java.lang.String</td>
 104  *   <td>UTF-8</td>
 105  *   <td>
 106  *       The value indicates the encoding scheme for the
 107  *       names of the entries in the Zip or JAR file.
 108  *   </td>
 109  * </tr>
 110  * <tr>
 111  *   <td scope="row">posix</td>
 112  *   <td>java.lang.Boolean</td>
 113  *   <td>false</td>
 114  *   <td>
 115  *       If the value is {@code true}, the created Zip file system will support
 116  *       the {@link java.nio.file.attribute.PosixFileAttributeView}.
 117  *   </td>
 118  * </tr>
 119  * <tr>
 120  *   <td scope="row">defaultOwner</td>
 121  *   <td>java.nio.file.attribute.UserPrincipal</td>
 122  *   <td>A user principal with its name set to the value of System property
 123  *       "{@code user.name}"</td>
 124  *   <td>
 125  *       The value will be the default owner for entries in the Zip
 126  *       file system.
 127  *   </td>
 128  * </tr>
 129  * <tr>
 130  *   <td scope="row">defaultGroup</td>
 131  *   <td>java.nio.file.attribute.GroupPrincipal</td>
 132  *   <td>A group principal with its name set to "{@code <zipfs_default>}"</td>
 133  *   <td>
 134  *       The value will be the default group for entries in the Zip
 135  *       file system.
 136  *   </td>
 137  * </tr>
 138  * <tr>
 139  *   <td scope="row">defaultPermissions</td>
 140  *   <td>java.util.Set&lt;{@link java.nio.file.attribute.PosixFilePermission}&gt;</td>
 141  *   <td>A set of {@link java.nio.file.attribute.PosixFilePermission#OWNER_READ OWNER_READ},
 142  *       {@link java.nio.file.attribute.PosixFilePermission#OWNER_WRITE OWNER_WRITE} and
 143  *       {@link java.nio.file.attribute.PosixFilePermission#GROUP_READ GROUP_READ}</td>
 144  *   <td>
 145  *       The value will be the default Set of permissions for entries in the Zip
 146  *       file system.
 147  *   </td>
 148  * </tr>
 149  * </tbody>
 150  * </table>
 151  *
 152  * <h3>Examples:</h3>
 153  *
 154  * Construct a new Zip file system that is identified by a URI.  If the Zip file does not exist,
 155  * it will be created:
 156  * <pre>
 157  * {@code
 158  *
 159  *     URI uri = URI.create("jar:file:/home/luckydog/tennisTeam.zip");
 160  *     Map<String, String> env = Map.of("create", "true");
 161  *     FileSystem zipfs = FileSystems.newFileSystem(uri, env);
 162  * }
 163  * </pre>
 164  *
 165  * Construct a new Zip file system that is identified by specifying a path
 166  * and using automatic file type detection. Iterate from the root of the JAR displaying each
 167  * found entry:
 168  * <pre>
 169  * {@code
 170  *
 171  *     FileSystem zipfs = FileSystems.newFileSystem(Path.of("helloworld.jar"), null);
 172  *     Path rootDir = zipfs.getPath("/");
 173  *     Files.walk(rootDir)
 174  *            .forEach(System.out::println);
 175  * }
 176  * </pre>
 177  * @provides java.nio.file.spi.FileSystemProvider
 178  * @moduleGraph
 179  * @since 9
 180  */
 181 module jdk.zipfs {
 182     provides java.nio.file.spi.FileSystemProvider with
 183         jdk.nio.zipfs.ZipFileSystemProvider;
 184 }