1 /*
 2  * Copyright (c) 2025, 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.internal.jimage;
26 
27 import java.io.InputStream;
28 import java.util.stream.Stream;
29 
30 /**
31  * Accesses the underlying resource entries in a jimage file.
32  *
33  * <p>This API is designed only for use by the jlink classes, which read the raw
34  * jimage files. Use the {@link ImageReader} API to read jimage contents at
35  * runtime to correctly account for preview mode.
36  *
37  * <p>This API ignores the {@code previewMode} of the {@link ImageReader} from
38  * which it is obtained, and returns an unmapped view of entries (e.g. allowing
39  * for direct access of resources in the {@code META-INF/preview/...} namespace).
40  *
41  * <p>It disallows access to resource directories (i.e. {@code "/modules/..."})
42  * or packages entries (i.e. {@code "/packages/..."}).
43  *
44  * @implNote This class needs to maintain JDK 8 source compatibility.
45  *
46  * It is used internally in the JDK to implement jimage/jrtfs access,
47  * but also compiled and delivered as part of the jrtfs.jar to support access
48  * to the jimage file provided by the shipped JDK by tools running on JDK 8.
49  */
50 public interface ResourceEntries {
51     /**
52      * Returns the jimage names for all resources in the given module, in
53      * random order. Entry names will always be prefixed by the given module
54      * name (e.g. {@code "/<module-name>/..."}).
55      */
56     Stream<String> getEntryNames(String module);
57 
58     /**
59      * Returns the (uncompressed) size of a resource given its jimage name.
60      *
61      * @throws java.util.NoSuchElementException if the resource does not exist.
62      */
63     long getSize(String name);
64 
65     /**
66      * Returns a copy of a resource's content given its jimage name.
67      *
68      * @throws java.util.NoSuchElementException if the resource does not exist.
69      */
70     byte[] getBytes(String name);
71 }