< prev index next >

src/java.base/share/classes/jdk/internal/jmod/JmodFile.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -57,11 +57,11 @@
             // validate the header
             byte[] magic = new byte[4];
             bis.read(magic);
             if (magic[0] != JMOD_MAGIC_NUMBER[0] ||
                 magic[1] != JMOD_MAGIC_NUMBER[1]) {
-                throw new IOException("Invalid jmod file: " + file.toString());
+                throw new IOException("Invalid JMOD file: " + file.toString());
             }
             if (magic[2] > JMOD_MAJOR_VERSION ||
                 (magic[2] == JMOD_MAJOR_VERSION && magic[3] > JMOD_MINOR_VERSION)) {
                 throw new IOException("Unsupported jmod version: " +
                     magic[2] + "." + magic[3] + " in " + file.toString());

@@ -129,10 +129,17 @@
         public String name() {
             return name;
         }
 
         /**
+         * Returns true if the entry is a directory in the JMOD file.
+         */
+        public boolean isDirectory() {
+            return zipEntry.isDirectory();
+        }
+
+        /**
          * Returns the size of this entry.
          */
         public long size() {
             return zipEntry.getSize();
         }

@@ -184,26 +191,26 @@
      * or {@code null} if not found.
      */
     public Entry getEntry(Section section, String name) {
         String entry = section.jmodDir() + "/" + name;
         ZipEntry ze = zipfile.getEntry(entry);
-        return (ze == null || ze.isDirectory()) ? null : new Entry(ze);
+        return (ze != null) ? new Entry(ze) : null;
     }
 
     /**
      * Opens an {@code InputStream} for reading the named entry of the given
-     * section in this jmod file.
+     * section in this JMOD file.
      *
      * @throws IOException if the named entry is not found, or I/O error
      *         occurs when reading it
      */
     public InputStream getInputStream(Section section, String name)
         throws IOException
     {
         String entry = section.jmodDir() + "/" + name;
         ZipEntry e = zipfile.getEntry(entry);
-        if (e == null || e.isDirectory()) {
+        if (e == null) {
             throw new IOException(name + " not found: " + file);
         }
         return zipfile.getInputStream(e);
     }
 

@@ -215,15 +222,14 @@
     public InputStream getInputStream(Entry entry) throws IOException {
         return zipfile.getInputStream(entry.zipEntry());
     }
 
     /**
-     * Returns a stream of non-directory entries in this jmod file.
+     * Returns a stream of entries in this JMOD file.
      */
     public Stream<Entry> stream() {
         return zipfile.stream()
-                      .filter(e -> !e.isDirectory())
                       .map(Entry::new);
     }
 
     @Override
     public void close() throws IOException {
< prev index next >