Browse Source

EFS in APPNOTE.TXT stands for 'Early Feature Specification' so our usage of it as 'use the general purpose field to signal UTF8' is wrong.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@911741 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
d3e00e275a
2 changed files with 27 additions and 19 deletions
  1. +12
    -12
      src/main/org/apache/tools/zip/ZipFile.java
  2. +15
    -7
      src/main/org/apache/tools/zip/ZipOutputStream.java

+ 12
- 12
src/main/org/apache/tools/zip/ZipFile.java View File

@@ -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 {
* <p>Also records the offsets for the data to read from the
* entries.</p>
*/
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));
}
}
}


+ 15
- 7
src/main/org/apache/tools/zip/ZipOutputStream.java View File

@@ -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 {
* <p>Defaults to true.</p>
*/
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


Loading…
Cancel
Save