8203328: Rename EFS in java.util.zip internals to something meaningful

Reviewed-by: sherman
This commit is contained in:
Martin Buchholz 2018-05-23 10:34:18 -07:00
parent e1bffce5a3
commit 42f7e3f69e
13 changed files with 41 additions and 41 deletions

View file

@ -54,7 +54,6 @@ class DeflaterOutputStream extends FilterOutputStream {
/** /**
* Indicates that the stream has been closed. * Indicates that the stream has been closed.
*/ */
private boolean closed = false; private boolean closed = false;
private final boolean syncFlush; private final boolean syncFlush;
@ -62,7 +61,7 @@ class DeflaterOutputStream extends FilterOutputStream {
/** /**
* Creates a new output stream with the specified compressor, * Creates a new output stream with the specified compressor,
* buffer size and flush mode. * buffer size and flush mode.
*
* @param out the output stream * @param out the output stream
* @param def the compressor ("deflater") * @param def the compressor ("deflater")
* @param size the output buffer size * @param size the output buffer size

View file

@ -74,11 +74,12 @@ class ZipConstants64 {
static final int ZIP64_EXTLEN = 16; // uncompressed size, 8-byte static final int ZIP64_EXTLEN = 16; // uncompressed size, 8-byte
/* /*
* Language encoding flag EFS * Language encoding flag (general purpose flag bit 11)
*
* If this bit is set the filename and comment fields for this
* entry must be encoded using UTF-8.
*/ */
static final int EFS = 0x800; // If this bit is set the filename and static final int USE_UTF8 = 0x800;
// comment fields for this file must be
// encoded using UTF-8.
/* /*
* Constants below are defined here (instead of in ZipConstants) * Constants below are defined here (instead of in ZipConstants)

View file

@ -354,7 +354,6 @@ class ZipEntry implements ZipConstants, Cloneable {
* or ZIP file formatted stream. * or ZIP file formatted stream.
* *
* @return The last access time of the entry, null if not specified * @return The last access time of the entry, null if not specified
* @see #setLastAccessTime(FileTime) * @see #setLastAccessTime(FileTime)
* @since 1.8 * @since 1.8
*/ */

View file

@ -377,7 +377,7 @@ class ZipFile implements ZipConstants, Closeable {
ensureOpen(); ensureOpen();
if (Objects.equals(lastEntryName, entry.name)) { if (Objects.equals(lastEntryName, entry.name)) {
pos = lastEntryPos; pos = lastEntryPos;
} else if (!zc.isUTF8() && (entry.flag & EFS) != 0) { } else if (!zc.isUTF8() && (entry.flag & USE_UTF8) != 0) {
pos = zsrc.getEntryPos(zc.getBytesUTF8(entry.name), false); pos = zsrc.getEntryPos(zc.getBytesUTF8(entry.name), false);
} else { } else {
pos = zsrc.getEntryPos(zc.getBytes(entry.name), false); pos = zsrc.getEntryPos(zc.getBytes(entry.name), false);
@ -605,7 +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);
if (!zc.isUTF8() && (CENFLG(cen, pos) & EFS) != 0) { if (!zc.isUTF8() && (CENFLG(cen, pos) & USE_UTF8) != 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);
@ -665,7 +665,7 @@ class ZipFile implements ZipConstants, Closeable {
// (1) null, invoked from iterator, or // (1) null, invoked from iterator, or
// (2) not equal to the name stored, a slash is appended during // (2) not equal to the name stored, a slash is appended during
// getEntryPos() search. // getEntryPos() search.
if (!zc.isUTF8() && (flag & EFS) != 0) { if (!zc.isUTF8() && (flag & USE_UTF8) != 0) {
name = zc.toStringUTF8(cen, pos + CENHDR, nlen); name = zc.toStringUTF8(cen, pos + CENHDR, nlen);
} else { } else {
name = zc.toString(cen, pos + CENHDR, nlen); name = zc.toString(cen, pos + CENHDR, nlen);
@ -684,7 +684,7 @@ class ZipFile implements ZipConstants, Closeable {
} }
if (clen != 0) { if (clen != 0) {
int start = pos + CENHDR + nlen + elen; int start = pos + CENHDR + nlen + elen;
if (!zc.isUTF8() && (flag & EFS) != 0) { if (!zc.isUTF8() && (flag & USE_UTF8) != 0) {
e.comment = zc.toStringUTF8(cen, start, clen); e.comment = zc.toStringUTF8(cen, start, clen);
} else { } else {
e.comment = zc.toString(cen, start, clen); e.comment = zc.toString(cen, start, clen);
@ -984,7 +984,8 @@ class ZipFile implements ZipConstants, Closeable {
} }
} }
/* The Zip file spec explicitly allows the LOC extra data size to /*
* The Zip file spec explicitly allows the LOC extra data size to
* be different from the CEN extra data size. Since we cannot trust * be different from the CEN extra data size. Since we cannot trust
* the CEN extra data size, we need to read the LOC to determine * the CEN extra data size, we need to read the LOC to determine
* the entry data offset. * the entry data offset.

View file

@ -283,7 +283,7 @@ class ZipInputStream extends InflaterInputStream implements ZipConstants {
if (get32(tmpbuf, 0) != LOCSIG) { if (get32(tmpbuf, 0) != LOCSIG) {
return null; return null;
} }
// get flag first, we need check EFS. // get flag first, we need check USE_UTF8.
flag = get16(tmpbuf, LOCFLG); flag = get16(tmpbuf, LOCFLG);
// get the entry name and create the ZipEntry first // get the entry name and create the ZipEntry first
int len = get16(tmpbuf, LOCNAM); int len = get16(tmpbuf, LOCNAM);
@ -295,8 +295,8 @@ class ZipInputStream extends InflaterInputStream implements ZipConstants {
b = new byte[blen]; b = new byte[blen];
} }
readFully(b, 0, len); readFully(b, 0, len);
// Force to use UTF-8 if the EFS bit is ON, even the cs is NOT UTF-8 // Force to use UTF-8 if the USE_UTF8 bit is ON
ZipEntry e = createZipEntry(((flag & EFS) != 0) ZipEntry e = createZipEntry(((flag & USE_UTF8) != 0)
? zc.toStringUTF8(b, len) ? zc.toStringUTF8(b, len)
: zc.toString(b, len)); : zc.toString(b, len));
// now get the remaining fields for the entry // now get the remaining fields for the entry

View file

@ -97,6 +97,7 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
throw new IOException("Stream closed"); throw new IOException("Stream closed");
} }
} }
/** /**
* Compression method for uncompressed (STORED) entries. * Compression method for uncompressed (STORED) entries.
*/ */
@ -232,7 +233,7 @@ class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
throw new ZipException("duplicate entry: " + e.name); throw new ZipException("duplicate entry: " + e.name);
} }
if (zc.isUTF8()) if (zc.isUTF8())
e.flag |= EFS; e.flag |= USE_UTF8;
current = new XEntry(e, written); current = new XEntry(e, written);
xentries.add(current); xentries.add(current);
writeLOC(current); writeLOC(current);

View file

@ -88,7 +88,6 @@ class ZipUtils {
} }
/** /**
/*
* Converts DOS time to Java time (number of milliseconds since epoch). * Converts DOS time to Java time (number of milliseconds since epoch).
*/ */
public static long dosToJavaTime(long dtime) { public static long dosToJavaTime(long dtime) {

View file

@ -46,7 +46,7 @@
* <li><a id="lang_encoding">APPENDIX D of</a> * <li><a id="lang_encoding">APPENDIX D of</a>
* <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT"> * <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
* PKWARE ZIP File Format Specification</a> - Language Encoding Flag * PKWARE ZIP File Format Specification</a> - Language Encoding Flag
* (EFS) to encode ZIP entry filename and comment fields using UTF-8. * to encode ZIP entry filename and comment fields using UTF-8.
* <li><a href="http://www.ietf.org/rfc/rfc1950.txt"> * <li><a href="http://www.ietf.org/rfc/rfc1950.txt">
* ZLIB Compressed Data Format Specification version 3.3</a> * ZLIB Compressed Data Format Specification version 3.3</a>
* &nbsp; * &nbsp;

View file

@ -43,11 +43,11 @@ class ZipConstants {
static final int METHOD_AES = 99; static final int METHOD_AES = 99;
/* /*
* General purpose big flag * General purpose bit flag
*/ */
static final int FLAG_ENCRYPTED = 0x01; static final int FLAG_ENCRYPTED = 0x01;
static final int FLAG_DATADESCR = 0x08; // crc, size and csize in dd static final int FLAG_DATADESCR = 0x08; // crc, size and csize in dd
static final int FLAG_EFS = 0x800; // If this bit is set the filename and static final int FLAG_USE_UTF8 = 0x800; // If this bit is set the filename and
// comment fields for this file must be // comment fields for this file must be
// encoded using UTF-8. // encoded using UTF-8.
/* /*

View file

@ -1374,7 +1374,7 @@ class ZipFileSystem extends FileSystem {
// store size, compressed size, and crc-32 in LOC header // store size, compressed size, and crc-32 in LOC header
e.flag = 0; e.flag = 0;
if (zc.isUTF8()) if (zc.isUTF8())
e.flag |= FLAG_EFS; e.flag |= FLAG_USE_UTF8;
OutputStream os; OutputStream os;
if (useTempFile) { if (useTempFile) {
e.file = getTempPathForEntry(null); e.file = getTempPathForEntry(null);

View file

@ -114,7 +114,7 @@ public class ZipCoding {
testZipInputStream(bis, cs, name, comment, bb); testZipInputStream(bis, cs, name, comment, bb);
if ("utf-8".equals(csn)) { if ("utf-8".equals(csn)) {
// EFS should be set // USE_UTF8 should be set
bis.reset(); bis.reset();
testZipInputStream(bis, Charset.forName("MS932"), name, comment, bb); testZipInputStream(bis, Charset.forName("MS932"), name, comment, bb);
} }