1 /* 2 * Copyright (c) 2014, 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 package jdk.tools.jlink.internal; 26 27 import java.io.IOException; 28 import java.io.InputStream; 29 import java.nio.file.Path; 30 import java.util.Objects; 31 import java.util.stream.Stream; 32 33 /** 34 * An Archive of all content, classes, resources, configuration files, and 35 * other, for a module. 36 */ 37 public interface Archive { 38 39 /** 40 * Entry is contained in an Archive 41 */ 42 public abstract class Entry { 43 44 public static enum EntryType { 45 MODULE_NAME, 46 CLASS_OR_RESOURCE, 47 NATIVE_LIB, 48 NATIVE_CMD, 49 CONFIG, 50 SERVICE; 51 } 52 53 private final String name; 54 private final EntryType type; 55 private final Archive archive; 56 private final String path; 57 58 public Entry(Archive archive, String path, String name, EntryType type) { 59 this.archive = Objects.requireNonNull(archive); 60 this.path = Objects.requireNonNull(path); 61 this.name = Objects.requireNonNull(name); 62 this.type = Objects.requireNonNull(type); 63 } 64 65 public Archive archive() { 66 return archive; 67 } 68 69 public String path() { 70 return path; 71 } 72 73 public EntryType type() { 74 return type; 75 } 76 77 /* 78 * Returns the name of this entry. 79 */ 80 public String name() { 81 return name; 82 } 83 84 @Override 85 public String toString() { 86 return "type " + type.name() + " path " + path; 87 } 88 89 /* 90 * Returns the number of uncompressed bytes for this entry. 91 */ 92 public abstract long size(); 93 94 public abstract InputStream stream() throws IOException; 95 } 96 97 /* 98 * The module name. 99 */ 100 String moduleName(); 101 102 /* 103 * Returns the path to this module's content 104 */ 105 Path getPath(); 106 107 /* 108 * Stream of Entry. 109 * The stream of entries needs to be closed after use 110 * since it might cover lazy I/O based resources. 111 * So callers need to use a try-with-resources block. 112 */ 113 Stream<Entry> entries(); 114 115 /* 116 * Open the archive 117 */ 118 void open() throws IOException; 119 120 /* 121 * Close the archive 122 */ 123 void close() throws IOException; 124 }