< prev index next >

src/java.base/share/classes/jdk/internal/jimage/Archive.java

Print this page

        

@@ -22,44 +22,97 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 package jdk.internal.jimage;
 
+import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.file.Path;
-import java.util.function.Consumer;
+import java.util.stream.Stream;
 
 /**
  * An Archive of all content, classes, resources, configuration files, and
  * other, for a module.
  */
 public interface Archive {
+
     /**
-     * The module name.
+     * Entry is contained in an Archive
      */
-    String moduleName();
+    public abstract class Entry {
+
+        public static enum EntryType {
+
+            MODULE_NAME,
+            CLASS_OR_RESOURCE,
+            NATIVE_LIB,
+            NATIVE_CMD,
+            CONFIG,
+            SERVICE;
+        }
+
+        private final String name;
+        private final EntryType type;
+        private final Archive archive;
+        private final String path;
+
+        public Entry(Archive archive, String path, String name, EntryType type) {
+            this.archive = archive;
+            this.path = path;
+            this.name = name;
+            this.type = type;
+        }
+
+        public Archive archive() {
+            return archive;
+        }
+
+        public String path() {
+            return path;
+        }
+
+        public EntryType type() {
+            return type;
+        }
 
     /**
-     * Visits all classes and resources.
+         * Returns the name of this entry.
      */
-    void visitResources(Consumer<Resource> consumer);
+        public String name() {
+            return name;
+        }
+
+        @Override
+        public String toString() {
+            return "type " + type.name() + " path " + path;
+        }
 
     /**
-     * Visits all entries in the Archive.
+         * Returns the number of uncompressed bytes for this entry.
      */
-    void visitEntries(Consumer<Entry> consumer) ;
+        public abstract long size();
+
+        public abstract InputStream stream() throws IOException;
+    }
 
     /**
-     * An entries in the Archive.
+     * The module name.
      */
-    interface Entry {
-        String getName();
-        InputStream getInputStream();
-        boolean isDirectory();
-    }
+    String moduleName();
+
+    /**
+     * Stream of Entry.
+     * The stream of entries needs to be closed after use since 
+     * (eg: it might cover lazy I/O based resources). 
+     * So callers will need to use a try-with-resources block.
+     */
+    Stream<Entry> entries();
+
+    /**
+     * Open the archive
+     */
+    void open() throws IOException;
 
     /**
-     * A Consumer suitable for writing Entries from this Archive.
+     * Close the archive
      */
-    Consumer<Entry> defaultImageWriter(Path path, OutputStream out);
+    void close() throws IOException;
 }
< prev index next >