42 import java.util.ArrayList;
43 import java.util.Arrays;
44 import java.util.Collections;
45 import java.util.Deque;
46 import java.util.Enumeration;
47 import java.util.HashMap;
48 import java.util.Iterator;
49 import java.util.Objects;
50 import java.util.NoSuchElementException;
51 import java.util.Set;
52 import java.util.Spliterator;
53 import java.util.Spliterators;
54 import java.util.WeakHashMap;
55 import java.util.function.Consumer;
56 import java.util.function.Function;
57 import java.util.function.IntFunction;
58 import java.util.jar.JarEntry;
59 import java.util.jar.JarFile;
60 import java.util.stream.Stream;
61 import java.util.stream.StreamSupport;
62 import jdk.internal.misc.JavaLangAccess;
63 import jdk.internal.misc.JavaUtilZipFileAccess;
64 import jdk.internal.misc.SharedSecrets;
65 import jdk.internal.misc.VM;
66 import jdk.internal.perf.PerfCounter;
67 import jdk.internal.ref.CleanerFactory;
68 import jdk.internal.vm.annotation.Stable;
69
70 import static java.util.zip.ZipConstants64.*;
71 import static java.util.zip.ZipUtils.*;
72
73 /**
74 * This class is used to read entries from a zip file.
75 *
76 * <p> Unless otherwise noted, passing a {@code null} argument to a constructor
77 * or method in this class will cause a {@link NullPointerException} to be
78 * thrown.
79 *
80 * @apiNote
81 * To release resources used by this {@code ZipFile}, the {@link #close()} method
82 * should be called explicitly or by try-with-resources. Subclasses are responsible
83 * for the cleanup of resources acquired by the subclass. Subclasses that override
84 * {@link #finalize()} in order to perform cleanup should be modified to use alternative
1119 public JarEntry getEntry(ZipFile zip, String name,
1120 Function<String, JarEntry> func) {
1121 return (JarEntry)zip.getEntry(name, func);
1122 }
1123 @Override
1124 public Enumeration<JarEntry> entries(ZipFile zip,
1125 Function<String, JarEntry> func) {
1126 return zip.entries(func);
1127 }
1128 @Override
1129 public Stream<JarEntry> stream(ZipFile zip,
1130 Function<String, JarEntry> func) {
1131 return zip.stream(func);
1132 }
1133 @Override
1134 public Stream<String> entryNameStream(ZipFile zip) {
1135 return zip.entryNameStream();
1136 }
1137 }
1138 );
1139 JLA = jdk.internal.misc.SharedSecrets.getJavaLangAccess();
1140 isWindows = VM.getSavedProperty("os.name").contains("Windows");
1141 }
1142
1143 private static class Source {
1144 private final Key key; // the key in files
1145 private int refs = 1;
1146
1147 private RandomAccessFile zfile; // zfile of the underlying zip file
1148 private byte[] cen; // CEN & ENDHDR
1149 private long locpos; // position of first LOC header (usually 0)
1150 private byte[] comment; // zip file comment
1151 // list of meta entries in META-INF dir
1152 private int[] metanames;
1153 private final boolean startsWithLoc; // true, if zip file starts with LOCSIG (usually true)
1154
1155 // A Hashmap for all entries.
1156 //
1157 // A cen entry of Zip/JAR file. As we have one for every entry in every active Zip/JAR,
1158 // We might have a lot of these in a typical system. In order to save space we don't
1159 // keep the name in memory, but merely remember a 32 bit {@code hash} value of the
|
42 import java.util.ArrayList;
43 import java.util.Arrays;
44 import java.util.Collections;
45 import java.util.Deque;
46 import java.util.Enumeration;
47 import java.util.HashMap;
48 import java.util.Iterator;
49 import java.util.Objects;
50 import java.util.NoSuchElementException;
51 import java.util.Set;
52 import java.util.Spliterator;
53 import java.util.Spliterators;
54 import java.util.WeakHashMap;
55 import java.util.function.Consumer;
56 import java.util.function.Function;
57 import java.util.function.IntFunction;
58 import java.util.jar.JarEntry;
59 import java.util.jar.JarFile;
60 import java.util.stream.Stream;
61 import java.util.stream.StreamSupport;
62 import jdk.internal.access.JavaLangAccess;
63 import jdk.internal.access.JavaUtilZipFileAccess;
64 import jdk.internal.access.SharedSecrets;
65 import jdk.internal.misc.VM;
66 import jdk.internal.perf.PerfCounter;
67 import jdk.internal.ref.CleanerFactory;
68 import jdk.internal.vm.annotation.Stable;
69
70 import static java.util.zip.ZipConstants64.*;
71 import static java.util.zip.ZipUtils.*;
72
73 /**
74 * This class is used to read entries from a zip file.
75 *
76 * <p> Unless otherwise noted, passing a {@code null} argument to a constructor
77 * or method in this class will cause a {@link NullPointerException} to be
78 * thrown.
79 *
80 * @apiNote
81 * To release resources used by this {@code ZipFile}, the {@link #close()} method
82 * should be called explicitly or by try-with-resources. Subclasses are responsible
83 * for the cleanup of resources acquired by the subclass. Subclasses that override
84 * {@link #finalize()} in order to perform cleanup should be modified to use alternative
1119 public JarEntry getEntry(ZipFile zip, String name,
1120 Function<String, JarEntry> func) {
1121 return (JarEntry)zip.getEntry(name, func);
1122 }
1123 @Override
1124 public Enumeration<JarEntry> entries(ZipFile zip,
1125 Function<String, JarEntry> func) {
1126 return zip.entries(func);
1127 }
1128 @Override
1129 public Stream<JarEntry> stream(ZipFile zip,
1130 Function<String, JarEntry> func) {
1131 return zip.stream(func);
1132 }
1133 @Override
1134 public Stream<String> entryNameStream(ZipFile zip) {
1135 return zip.entryNameStream();
1136 }
1137 }
1138 );
1139 JLA = SharedSecrets.getJavaLangAccess();
1140 isWindows = VM.getSavedProperty("os.name").contains("Windows");
1141 }
1142
1143 private static class Source {
1144 private final Key key; // the key in files
1145 private int refs = 1;
1146
1147 private RandomAccessFile zfile; // zfile of the underlying zip file
1148 private byte[] cen; // CEN & ENDHDR
1149 private long locpos; // position of first LOC header (usually 0)
1150 private byte[] comment; // zip file comment
1151 // list of meta entries in META-INF dir
1152 private int[] metanames;
1153 private final boolean startsWithLoc; // true, if zip file starts with LOCSIG (usually true)
1154
1155 // A Hashmap for all entries.
1156 //
1157 // A cen entry of Zip/JAR file. As we have one for every entry in every active Zip/JAR,
1158 // We might have a lot of these in a typical system. In order to save space we don't
1159 // keep the name in memory, but merely remember a 32 bit {@code hash} value of the
|