diff --git a/src/main/org/apache/tools/zip/ZipFile.java b/src/main/org/apache/tools/zip/ZipFile.java index a2fbfc80c..acb6f3d1b 100644 --- a/src/main/org/apache/tools/zip/ZipFile.java +++ b/src/main/org/apache/tools/zip/ZipFile.java @@ -182,8 +182,8 @@ public class ZipFile { archive = new RandomAccessFile(f, "r"); boolean success = false; try { - Map entriesWithoutEFS = populateFromCentralDirectory(); - resolveLocalFileHeaderData(entriesWithoutEFS); + Map entriesWithoutUTF8Flag = populateFromCentralDirectory(); + resolveLocalFileHeaderData(entriesWithoutUTF8Flag); success = true; } finally { if (!success) { @@ -308,7 +308,7 @@ public class ZipFile { */ private Map populateFromCentralDirectory() throws IOException { - HashMap noEFS = new HashMap(); + HashMap noUTF8Flag = new HashMap(); positionAtCentralDirectory(); @@ -334,10 +334,10 @@ public class ZipFile { off += SHORT; // skip version info final int generalPurposeFlag = ZipShort.getValue(cfh, off); - final boolean hasEFS = - (generalPurposeFlag & ZipOutputStream.EFS_FLAG) != 0; + final boolean hasUTF8Flag = + (generalPurposeFlag & ZipOutputStream.UFT8_NAMES_FLAG) != 0; final ZipEncoding entryEncoding = - hasEFS ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding; + hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding; off += SHORT; @@ -400,11 +400,11 @@ public class ZipFile { archive.readFully(signatureBytes); sig = ZipLong.getValue(signatureBytes); - if (!hasEFS && useUnicodeExtraFields) { - noEFS.put(ze, new NameAndComment(fileName, comment)); + if (!hasUTF8Flag && useUnicodeExtraFields) { + noUTF8Flag.put(ze, new NameAndComment(fileName, comment)); } } - return noEFS; + return noUTF8Flag; } private static final int MIN_EOCD_SIZE = @@ -499,7 +499,7 @@ public class ZipFile { *

Also records the offsets for the data to read from the * entries.

*/ - private void resolveLocalFileHeaderData(Map entriesWithoutEFS) + private void resolveLocalFileHeaderData(Map entriesWithoutUTF8Flag) throws IOException { Enumeration e = getEntries(); while (e.hasMoreElements()) { @@ -531,10 +531,10 @@ public class ZipFile { offsetEntry.dataOffset = offset + LFH_OFFSET_FOR_FILENAME_LENGTH + SHORT + SHORT + fileNameLen + extraFieldLen; - if (entriesWithoutEFS.containsKey(ze)) { + if (entriesWithoutUTF8Flag.containsKey(ze)) { setNameAndCommentFromExtraFields(ze, (NameAndComment) - entriesWithoutEFS.get(ze)); + entriesWithoutUTF8Flag.get(ze)); } } } diff --git a/src/main/org/apache/tools/zip/ZipOutputStream.java b/src/main/org/apache/tools/zip/ZipOutputStream.java index 0ddb17a7d..c9e3125fa 100644 --- a/src/main/org/apache/tools/zip/ZipOutputStream.java +++ b/src/main/org/apache/tools/zip/ZipOutputStream.java @@ -96,11 +96,18 @@ public class ZipOutputStream extends FilterOutputStream { */ static final String DEFAULT_ENCODING = null; - /** + /** + * General purpose flag, which indicates that filenames are + * written in utf-8. + */ + public static final int UFT8_NAMES_FLAG = 1 << 11; + + /** * General purpose flag, which indicates that filenames are * written in utf-8. + * @deprecated use {@link #UFT8_NAMES_FLAG} instead */ - public static final int EFS_FLAG = 1 << 11; + public static final int EFS_FLAG = UFT8_NAMES_FLAG; /** * Current entry. @@ -265,9 +272,10 @@ public class ZipOutputStream extends FilterOutputStream { private RandomAccessFile raf = null; /** - * whether to use the EFS flag when writing UTF-8 filenames or not. + * whether to use the general purpose bit flag when writing UTF-8 + * filenames or not. */ - private boolean useEFS = true; + private boolean useUTF8Flag = true; /** * Whether to encode non-encodable file names as UTF-8. @@ -341,7 +349,7 @@ public class ZipOutputStream extends FilterOutputStream { public void setEncoding(final String encoding) { this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); - useEFS &= ZipEncodingHelper.isUTF8(encoding); + useUTF8Flag &= ZipEncodingHelper.isUTF8(encoding); } /** @@ -362,7 +370,7 @@ public class ZipOutputStream extends FilterOutputStream { *

Defaults to true.

*/ public void setUseLanguageEncodingFlag(boolean b) { - useEFS = b && ZipEncodingHelper.isUTF8(encoding); + useUTF8Flag = b && ZipEncodingHelper.isUTF8(encoding); } /** @@ -1050,7 +1058,7 @@ public class ZipOutputStream extends FilterOutputStream { // CheckStyle:MagicNumber OFF int versionNeededToExtract = 10; - int generalPurposeFlag = (useEFS || utfFallback) ? EFS_FLAG : 0; + int generalPurposeFlag = (useUTF8Flag || utfFallback) ? UFT8_NAMES_FLAG : 0; if (zipMethod == DEFLATED && raf == null) { // requires version 2 as we are going to store length info // in the data descriptor