8200124: Various cleanups in jar/zip

Reviewed-by: sherman, ulfzibis
This commit is contained in:
Martin Buchholz 2018-03-28 21:14:03 -07:00
parent 6f37b4cbce
commit 08adfe31b3
4 changed files with 8 additions and 11 deletions

View file

@ -148,7 +148,7 @@ public class Manifest implements Cloneable {
DataOutputStream dos = new DataOutputStream(out); DataOutputStream dos = new DataOutputStream(out);
// Write out the main attributes for the manifest // Write out the main attributes for the manifest
attr.writeMain(dos); attr.writeMain(dos);
// Now write out the pre-entry attributes // Now write out the per-entry attributes
for (Map.Entry<String, Attributes> e : entries.entrySet()) { for (Map.Entry<String, Attributes> e : entries.entrySet()) {
StringBuffer buffer = new StringBuffer("Name: "); StringBuffer buffer = new StringBuffer("Name: ");
String value = e.getKey(); String value = e.getKey();

View file

@ -77,8 +77,7 @@ class ZipCoder {
String toString(byte[] ba, int off, int length) { String toString(byte[] ba, int off, int length) {
try { try {
return decoder().decode(ByteBuffer.wrap(ba, off, length)).toString(); return decoder().decode(ByteBuffer.wrap(ba, off, length)).toString();
} catch (CharacterCodingException x) { } catch (CharacterCodingException x) {
throw new IllegalArgumentException(x); throw new IllegalArgumentException(x);
} }

View file

@ -64,6 +64,7 @@ import jdk.internal.misc.SharedSecrets;
import jdk.internal.misc.VM; import jdk.internal.misc.VM;
import jdk.internal.perf.PerfCounter; import jdk.internal.perf.PerfCounter;
import jdk.internal.ref.CleanerFactory; import jdk.internal.ref.CleanerFactory;
import jdk.internal.vm.annotation.Stable;
import static java.util.zip.ZipConstants64.*; import static java.util.zip.ZipConstants64.*;
import static java.util.zip.ZipUtils.*; import static java.util.zip.ZipUtils.*;
@ -98,14 +99,14 @@ class ZipFile implements ZipConstants, Closeable {
private final String name; // zip file name private final String name; // zip file name
private volatile boolean closeRequested; private volatile boolean closeRequested;
private ZipCoder zc; private final @Stable ZipCoder zc;
// The "resource" used by this zip file that needs to be // The "resource" used by this zip file that needs to be
// cleaned after use. // cleaned after use.
// a) the input streams that need to be closed // a) the input streams that need to be closed
// b) the list of cached Inflater objects // b) the list of cached Inflater objects
// c) the "native" source of this zip file. // c) the "native" source of this zip file.
private final CleanableResource res; private final @Stable CleanableResource res;
private static final int STORED = ZipEntry.STORED; private static final int STORED = ZipEntry.STORED;
private static final int DEFLATED = ZipEntry.DEFLATED; private static final int DEFLATED = ZipEntry.DEFLATED;
@ -369,7 +370,7 @@ class ZipFile implements ZipConstants, Closeable {
public InputStream getInputStream(ZipEntry entry) throws IOException { public InputStream getInputStream(ZipEntry entry) throws IOException {
Objects.requireNonNull(entry, "entry"); Objects.requireNonNull(entry, "entry");
int pos = -1; int pos = -1;
ZipFileInputStream in = null; ZipFileInputStream in;
Source zsrc = res.zsrc; Source zsrc = res.zsrc;
Set<InputStream> istreams = res.istreams; Set<InputStream> istreams = res.istreams;
synchronized (this) { synchronized (this) {
@ -604,9 +605,7 @@ class ZipFile implements ZipConstants, Closeable {
private String getEntryName(int pos) { private String getEntryName(int pos) {
byte[] cen = res.zsrc.cen; byte[] cen = res.zsrc.cen;
int nlen = CENNAM(cen, pos); int nlen = CENNAM(cen, pos);
int clen = CENCOM(cen, pos); if (!zc.isUTF8() && (CENFLG(cen, pos) & EFS) != 0) {
int flag = CENFLG(cen, pos);
if (!zc.isUTF8() && (flag & EFS) != 0) {
return zc.toStringUTF8(cen, pos + CENHDR, nlen); return zc.toStringUTF8(cen, pos + CENHDR, nlen);
} else { } else {
return zc.toString(cen, pos + CENHDR, nlen); return zc.toString(cen, pos + CENHDR, nlen);
@ -1218,7 +1217,7 @@ class ZipFile implements ZipConstants, Closeable {
static Source get(File file, boolean toDelete) throws IOException { static Source get(File file, boolean toDelete) throws IOException {
Key key = new Key(file, Key key = new Key(file,
Files.readAttributes(file.toPath(), BasicFileAttributes.class)); Files.readAttributes(file.toPath(), BasicFileAttributes.class));
Source src = null; Source src;
synchronized (files) { synchronized (files) {
src = files.get(key); src = files.get(key);
if (src != null) { if (src != null) {

View file

@ -52,7 +52,6 @@ public class Manifest {
private Hashtable<String, MessageHeader> tableEntries = new Hashtable<>(); private Hashtable<String, MessageHeader> tableEntries = new Hashtable<>();
static final String[] hashes = {"SHA"}; static final String[] hashes = {"SHA"};
static final byte[] EOL = {(byte)'\r', (byte)'\n'};
static final boolean debug = false; static final boolean debug = false;
static final String VERSION = "1.0"; static final String VERSION = "1.0";