< prev index next >

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JarArchive.java

Print this page




  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 package jdk.tools.jlink.internal;
  27 
  28 import java.io.IOException;
  29 import java.io.InputStream;
  30 import java.io.UncheckedIOException;
  31 import java.nio.file.Path;
  32 import java.util.Objects;
  33 import java.util.jar.JarFile;
  34 import java.util.stream.Stream;
  35 import java.util.zip.ZipEntry;
  36 import java.util.zip.ZipFile;
  37 import jdk.internal.util.jar.VersionedStream;
  38 import jdk.tools.jlink.internal.Archive.Entry.EntryType;
  39 
  40 /**
  41  * An Archive backed by a jar file.
  42  */
  43 public abstract class JarArchive implements Archive {
  44 
  45     /**
  46      * An entry located in a jar file.
  47      */
  48     public class JarEntry extends Entry {
  49 
  50         private final long size;
  51         private final ZipEntry entry;
  52         private final ZipFile file;
  53 
  54         JarEntry(String path, String name, EntryType type, ZipFile file, ZipEntry entry) {
  55             super(JarArchive.this, path, name, type);
  56             this.entry = Objects.requireNonNull(entry);
  57             this.file = Objects.requireNonNull(file);


  88 
  89     @Override
  90     public String moduleName() {
  91         return moduleName;
  92     }
  93 
  94     @Override
  95     public Path getPath() {
  96         return file;
  97     }
  98 
  99     @Override
 100     public Stream<Entry> entries() {
 101         try {
 102             if (jarFile == null) {
 103                 open();
 104             }
 105         } catch (IOException ioe) {
 106             throw new UncheckedIOException(ioe);
 107         }
 108         return VersionedStream.stream(jarFile)
 109                 .filter(je -> !je.isDirectory())
 110                 .map(this::toEntry);
 111     }
 112 
 113     abstract EntryType toEntryType(String entryName);
 114 
 115     abstract String getFileName(String entryName);
 116 
 117     abstract Entry toEntry(ZipEntry ze);
 118 
 119     @Override
 120     public void close() throws IOException {
 121         if (jarFile != null) {
 122             jarFile.close();
 123         }
 124     }
 125 
 126     @Override
 127     public void open() throws IOException {
 128         if (jarFile != null) {


  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 package jdk.tools.jlink.internal;
  27 
  28 import java.io.IOException;
  29 import java.io.InputStream;
  30 import java.io.UncheckedIOException;
  31 import java.nio.file.Path;
  32 import java.util.Objects;
  33 import java.util.jar.JarFile;
  34 import java.util.stream.Stream;
  35 import java.util.zip.ZipEntry;
  36 import java.util.zip.ZipFile;

  37 import jdk.tools.jlink.internal.Archive.Entry.EntryType;
  38 
  39 /**
  40  * An Archive backed by a jar file.
  41  */
  42 public abstract class JarArchive implements Archive {
  43 
  44     /**
  45      * An entry located in a jar file.
  46      */
  47     public class JarEntry extends Entry {
  48 
  49         private final long size;
  50         private final ZipEntry entry;
  51         private final ZipFile file;
  52 
  53         JarEntry(String path, String name, EntryType type, ZipFile file, ZipEntry entry) {
  54             super(JarArchive.this, path, name, type);
  55             this.entry = Objects.requireNonNull(entry);
  56             this.file = Objects.requireNonNull(file);


  87 
  88     @Override
  89     public String moduleName() {
  90         return moduleName;
  91     }
  92 
  93     @Override
  94     public Path getPath() {
  95         return file;
  96     }
  97 
  98     @Override
  99     public Stream<Entry> entries() {
 100         try {
 101             if (jarFile == null) {
 102                 open();
 103             }
 104         } catch (IOException ioe) {
 105             throw new UncheckedIOException(ioe);
 106         }
 107         return jarFile.versionedStream()
 108                 .filter(je -> !je.isDirectory())
 109                 .map(this::toEntry);
 110     }
 111 
 112     abstract EntryType toEntryType(String entryName);
 113 
 114     abstract String getFileName(String entryName);
 115 
 116     abstract Entry toEntry(ZipEntry ze);
 117 
 118     @Override
 119     public void close() throws IOException {
 120         if (jarFile != null) {
 121             jarFile.close();
 122         }
 123     }
 124 
 125     @Override
 126     public void open() throws IOException {
 127         if (jarFile != null) {
< prev index next >