equal
deleted
inserted
replaced
62 import jdk.internal.misc.JavaUtilZipFileAccess; |
62 import jdk.internal.misc.JavaUtilZipFileAccess; |
63 import jdk.internal.misc.SharedSecrets; |
63 import jdk.internal.misc.SharedSecrets; |
64 import jdk.internal.misc.VM; |
64 import jdk.internal.misc.VM; |
65 import jdk.internal.perf.PerfCounter; |
65 import jdk.internal.perf.PerfCounter; |
66 import jdk.internal.ref.CleanerFactory; |
66 import jdk.internal.ref.CleanerFactory; |
|
67 import jdk.internal.vm.annotation.Stable; |
67 |
68 |
68 import static java.util.zip.ZipConstants64.*; |
69 import static java.util.zip.ZipConstants64.*; |
69 import static java.util.zip.ZipUtils.*; |
70 import static java.util.zip.ZipUtils.*; |
70 |
71 |
71 /** |
72 /** |
96 public |
97 public |
97 class ZipFile implements ZipConstants, Closeable { |
98 class ZipFile implements ZipConstants, Closeable { |
98 |
99 |
99 private final String name; // zip file name |
100 private final String name; // zip file name |
100 private volatile boolean closeRequested; |
101 private volatile boolean closeRequested; |
101 private ZipCoder zc; |
102 private final @Stable ZipCoder zc; |
102 |
103 |
103 // The "resource" used by this zip file that needs to be |
104 // The "resource" used by this zip file that needs to be |
104 // cleaned after use. |
105 // cleaned after use. |
105 // a) the input streams that need to be closed |
106 // a) the input streams that need to be closed |
106 // b) the list of cached Inflater objects |
107 // b) the list of cached Inflater objects |
107 // c) the "native" source of this zip file. |
108 // c) the "native" source of this zip file. |
108 private final CleanableResource res; |
109 private final @Stable CleanableResource res; |
109 |
110 |
110 private static final int STORED = ZipEntry.STORED; |
111 private static final int STORED = ZipEntry.STORED; |
111 private static final int DEFLATED = ZipEntry.DEFLATED; |
112 private static final int DEFLATED = ZipEntry.DEFLATED; |
112 |
113 |
113 /** |
114 /** |
367 * @throws IllegalStateException if the zip file has been closed |
368 * @throws IllegalStateException if the zip file has been closed |
368 */ |
369 */ |
369 public InputStream getInputStream(ZipEntry entry) throws IOException { |
370 public InputStream getInputStream(ZipEntry entry) throws IOException { |
370 Objects.requireNonNull(entry, "entry"); |
371 Objects.requireNonNull(entry, "entry"); |
371 int pos = -1; |
372 int pos = -1; |
372 ZipFileInputStream in = null; |
373 ZipFileInputStream in; |
373 Source zsrc = res.zsrc; |
374 Source zsrc = res.zsrc; |
374 Set<InputStream> istreams = res.istreams; |
375 Set<InputStream> istreams = res.istreams; |
375 synchronized (this) { |
376 synchronized (this) { |
376 ensureOpen(); |
377 ensureOpen(); |
377 if (Objects.equals(lastEntryName, entry.name)) { |
378 if (Objects.equals(lastEntryName, entry.name)) { |
602 } |
603 } |
603 |
604 |
604 private String getEntryName(int pos) { |
605 private String getEntryName(int pos) { |
605 byte[] cen = res.zsrc.cen; |
606 byte[] cen = res.zsrc.cen; |
606 int nlen = CENNAM(cen, pos); |
607 int nlen = CENNAM(cen, pos); |
607 int clen = CENCOM(cen, pos); |
608 if (!zc.isUTF8() && (CENFLG(cen, pos) & EFS) != 0) { |
608 int flag = CENFLG(cen, pos); |
|
609 if (!zc.isUTF8() && (flag & EFS) != 0) { |
|
610 return zc.toStringUTF8(cen, pos + CENHDR, nlen); |
609 return zc.toStringUTF8(cen, pos + CENHDR, nlen); |
611 } else { |
610 } else { |
612 return zc.toString(cen, pos + CENHDR, nlen); |
611 return zc.toString(cen, pos + CENHDR, nlen); |
613 } |
612 } |
614 } |
613 } |
1216 |
1215 |
1217 |
1216 |
1218 static Source get(File file, boolean toDelete) throws IOException { |
1217 static Source get(File file, boolean toDelete) throws IOException { |
1219 Key key = new Key(file, |
1218 Key key = new Key(file, |
1220 Files.readAttributes(file.toPath(), BasicFileAttributes.class)); |
1219 Files.readAttributes(file.toPath(), BasicFileAttributes.class)); |
1221 Source src = null; |
1220 Source src; |
1222 synchronized (files) { |
1221 synchronized (files) { |
1223 src = files.get(key); |
1222 src = files.get(key); |
1224 if (src != null) { |
1223 if (src != null) { |
1225 src.refs++; |
1224 src.refs++; |
1226 return src; |
1225 return src; |