git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1210522 13f79535-47bb-0310-9956-ffa450edef68master
@@ -356,6 +356,7 @@ Ulrich Schmidt | |||||
Valentino Miazzo | Valentino Miazzo | ||||
Victor Toni | Victor Toni | ||||
Vincent Legoll | Vincent Legoll | ||||
Volker Leidl | |||||
Waldek Herka | Waldek Herka | ||||
Will Wang | Will Wang | ||||
William Bernardet | William Bernardet | ||||
@@ -112,6 +112,9 @@ Fixed bugs: | |||||
quoted. | quoted. | ||||
Bugzilla Report 31667. | Bugzilla Report 31667. | ||||
* ZipFile didn't work properly for archives using unicode extra | |||||
fields rather than UTF-8 filenames and the EFS-Flag. | |||||
Other changes: | Other changes: | ||||
-------------- | -------------- | ||||
@@ -1436,6 +1436,10 @@ | |||||
<first>Vincent</first> | <first>Vincent</first> | ||||
<last>Legoll</last> | <last>Legoll</last> | ||||
</name> | </name> | ||||
<name> | |||||
<first>Volker</first> | |||||
<last>Leidl</last> | |||||
</name> | |||||
<name> | <name> | ||||
<first>Will</first> | <first>Will</first> | ||||
<last>Wang</last> | <last>Wang</last> | ||||
@@ -27,6 +27,7 @@ import java.util.Collections; | |||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.Enumeration; | import java.util.Enumeration; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.HashSet; | |||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.zip.CRC32; | import java.util.zip.CRC32; | ||||
import java.util.zip.Inflater; | import java.util.zip.Inflater; | ||||
@@ -509,7 +510,7 @@ public class ZipFile { | |||||
*/ | */ | ||||
private void resolveLocalFileHeaderData(Map entriesWithoutUTF8Flag) | private void resolveLocalFileHeaderData(Map entriesWithoutUTF8Flag) | ||||
throws IOException { | throws IOException { | ||||
Enumeration e = getEntries(); | |||||
Enumeration e = Collections.enumeration(new HashSet(entries.keySet())); | |||||
while (e.hasMoreElements()) { | while (e.hasMoreElements()) { | ||||
ZipEntry ze = (ZipEntry) e.nextElement(); | ZipEntry ze = (ZipEntry) e.nextElement(); | ||||
OffsetEntry offsetEntry = (OffsetEntry) entries.get(ze); | OffsetEntry offsetEntry = (OffsetEntry) entries.get(ze); | ||||
@@ -540,9 +541,14 @@ public class ZipFile { | |||||
+ SHORT + SHORT + fileNameLen + extraFieldLen; | + SHORT + SHORT + fileNameLen + extraFieldLen; | ||||
if (entriesWithoutUTF8Flag.containsKey(ze)) { | if (entriesWithoutUTF8Flag.containsKey(ze)) { | ||||
// changing the name of a ZipEntry is going to change | |||||
// the hashcode | |||||
// - see https://issues.apache.org/jira/browse/COMPRESS-164 | |||||
entries.remove(ze); | |||||
setNameAndCommentFromExtraFields(ze, | setNameAndCommentFromExtraFields(ze, | ||||
(NameAndComment) | (NameAndComment) | ||||
entriesWithoutUTF8Flag.get(ze)); | entriesWithoutUTF8Flag.get(ze)); | ||||
entries.put(ze, offsetEntry); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -19,6 +19,7 @@ | |||||
package org.apache.tools.zip; | package org.apache.tools.zip; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.InputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.UnsupportedEncodingException; | import java.io.UnsupportedEncodingException; | ||||
import java.nio.ByteBuffer; | import java.nio.ByteBuffer; | ||||
@@ -81,9 +82,9 @@ public class UTF8ZipFilesTest extends TestCase { | |||||
try { | try { | ||||
createTestFile(file, US_ASCII, false, true); | createTestFile(file, US_ASCII, false, true); | ||||
zf = new ZipFile(file, US_ASCII, true); | zf = new ZipFile(file, US_ASCII, true); | ||||
assertNotNull(zf.getEntry(ASCII_TXT)); | |||||
assertNotNull(zf.getEntry(EURO_FOR_DOLLAR_TXT)); | |||||
assertNotNull(zf.getEntry(OIL_BARREL_TXT)); | |||||
assertCanRead(zf, ASCII_TXT); | |||||
assertCanRead(zf, EURO_FOR_DOLLAR_TXT); | |||||
assertCanRead(zf, OIL_BARREL_TXT); | |||||
} finally { | } finally { | ||||
ZipFile.closeQuietly(zf); | ZipFile.closeQuietly(zf); | ||||
if (file.exists()) { | if (file.exists()) { | ||||
@@ -232,5 +233,17 @@ public class UTF8ZipFilesTest extends TestCase { | |||||
} | } | ||||
} | } | ||||
private static void assertCanRead(ZipFile zf, String fileName) throws IOException { | |||||
ZipEntry entry = zf.getEntry(fileName); | |||||
assertNotNull("Entry " + fileName + " doesn't exist", entry); | |||||
InputStream is = zf.getInputStream(entry); | |||||
assertNotNull("InputStream is null", is); | |||||
try { | |||||
is.read(); | |||||
} finally { | |||||
is.close(); | |||||
} | |||||
} | |||||
} | } | ||||