You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2018/01/07 09:34:15 UTC
[1/9] commons-compress git commit: Expose source of name/comment
field value via dedicated methods
Repository: commons-compress
Updated Branches:
refs/heads/master c36fef5f5 -> ced2075ca
Expose source of name/comment field value via dedicated methods
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/f488eba1
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/f488eba1
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/f488eba1
Branch: refs/heads/master
Commit: f488eba11289fae758646a21f86b2ad6c4156538
Parents: e83b4d8
Author: Damiano Albani <da...@gmail.com>
Authored: Tue Dec 12 17:07:24 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri Jan 5 17:25:27 2018 +0100
----------------------------------------------------------------------
.../compress/archivers/zip/ZipArchiveEntry.java | 53 ++++++++++++++++----
.../commons/compress/archivers/zip/ZipFile.java | 32 ++++--------
.../commons/compress/archivers/zip/ZipUtil.java | 4 +-
3 files changed, 54 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/f488eba1/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
index 13eae15..846b6f7 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
@@ -59,6 +59,17 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
private static final int SHORT_SHIFT = 16;
private static final byte[] EMPTY = new byte[0];
+ public enum NameSource {
+ NAME,
+ NAME_WITH_EFS_FLAG,
+ UNICODE_EXTRA_FIELD
+ }
+
+ public enum CommentSource {
+ COMMENT,
+ UNICODE_EXTRA_FIELD
+ }
+
/**
* The {@link java.util.zip.ZipEntry} base class only supports
* the compression methods STORED and DEFLATED. We override the
@@ -98,8 +109,9 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
private long localHeaderOffset = OFFSET_UNKNOWN;
private long dataOffset = OFFSET_UNKNOWN;
private boolean isStreamContiguous = false;
- private boolean hasUnicodeName = false;
- private boolean hasUnicodeComment = false;
+ private NameSource nameSource = NameSource.NAME;
+ private CommentSource commentSource = CommentSource.COMMENT;
+
/**
* Creates a new zip entry with the specified name.
@@ -929,19 +941,40 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
this.rawFlag = rawFlag;
}
- public boolean hasUnicodeName() {
- return hasUnicodeName;
+ /**
+ * The source of the name field value.
+ * @return source of the name field value
+ * @since 1.16
+ */
+ public NameSource getNameSource() {
+ return nameSource;
}
- public void setHasUnicodeName(boolean hasUnicodeName) {
- this.hasUnicodeName = hasUnicodeName;
+ /**
+ * Sets the source of the name field value.
+ * @param nameSource source of the name field value
+ * @since 1.16
+ */
+ public void setNameSource(NameSource nameSource) {
+ this.nameSource = nameSource;
}
- public boolean hasUnicodeComment() {
- return hasUnicodeComment;
+ /**
+ * The source of the comment field value.
+ * @return source of the comment field value
+ * @since 1.16
+ */
+ public CommentSource getCommentSource() {
+ return commentSource;
}
- public void setHasUnicodeComment(boolean hasUnicodeComment) {
- this.hasUnicodeComment = hasUnicodeComment;
+ /**
+ * Sets the source of the comment field value.
+ * @param commentSource source of the comment field value
+ * @since 1.16
+ */
+ public void setCommentSource(CommentSource commentSource) {
+ this.commentSource = commentSource;
}
+
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/f488eba1/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
index a76104f..1e30f31 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
@@ -17,38 +17,21 @@
*/
package org.apache.commons.compress.archivers.zip;
-import java.io.BufferedInputStream;
-import java.io.Closeable;
-import java.io.EOFException;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
+import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
+import org.apache.commons.compress.utils.IOUtils;
+
+import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Enumeration;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import java.util.zip.ZipException;
-import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
-import org.apache.commons.compress.utils.IOUtils;
-
-import static org.apache.commons.compress.archivers.zip.ZipConstants.DWORD;
-import static org.apache.commons.compress.archivers.zip.ZipConstants.SHORT;
-import static org.apache.commons.compress.archivers.zip.ZipConstants.WORD;
-import static org.apache.commons.compress.archivers.zip.ZipConstants.ZIP64_MAGIC;
-import static org.apache.commons.compress.archivers.zip.ZipConstants.ZIP64_MAGIC_SHORT;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.*;
/**
* Replacement for <code>java.util.ZipFile</code>.
@@ -653,6 +636,9 @@ public class ZipFile implements Closeable {
final boolean hasUTF8Flag = gpFlag.usesUTF8ForNames();
final ZipEncoding entryEncoding =
hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding;
+ if (hasUTF8Flag) {
+ ze.setNameSource(ZipArchiveEntry.NameSource.NAME_WITH_EFS_FLAG);
+ }
ze.setGeneralPurposeBit(gpFlag);
ze.setRawFlag(ZipShort.getValue(cfhBuf, off));
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/f488eba1/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
index 11f7315..6342cd1 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
@@ -239,7 +239,7 @@ public abstract class ZipUtil {
originalNameBytes);
if (newName != null && !originalName.equals(newName)) {
ze.setName(newName);
- ze.setHasUnicodeName(true);
+ ze.setNameSource(ZipArchiveEntry.NameSource.UNICODE_EXTRA_FIELD);
}
if (commentBytes != null && commentBytes.length > 0) {
@@ -249,7 +249,7 @@ public abstract class ZipUtil {
getUnicodeStringIfOriginalMatches(cmt, commentBytes);
if (newComment != null) {
ze.setComment(newComment);
- ze.setHasUnicodeComment(true);
+ ze.setCommentSource(ZipArchiveEntry.CommentSource.UNICODE_EXTRA_FIELD);
}
}
}
[7/9] commons-compress git commit: record change
Posted by bo...@apache.org.
record change
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/eb32d62f
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/eb32d62f
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/eb32d62f
Branch: refs/heads/master
Commit: eb32d62fac68a7b046d32952af9e83c1fc2746c1
Parents: 0517c7f
Author: Stefan Bodewig <bo...@apache.org>
Authored: Fri Jan 5 18:01:14 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri Jan 5 18:01:14 2018 +0100
----------------------------------------------------------------------
src/changes/changes.xml | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/eb32d62f/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8fda4bf..d640f2a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -76,6 +76,11 @@ The <action> type attribute can be add,update,fix,remove.
Updated XZ for Java dependency to 1.8 in order to pick up bug
fix to LZMA2InputStream's available method.
</action>
+ <action type="update" date="2018-01-05" issue="COMPRESS-429"
+ due-to="Damiano Albani">
+ ZipArchiveEntry now exposes how the name or comment have been
+ determined when the entry was read.
+ </action>
</release>
<release version="1.15" date="2017-10-17"
description="Release 1.15
[5/9] commons-compress git commit: COMPRESS-429 javadocs
Posted by bo...@apache.org.
COMPRESS-429 javadocs
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/83923434
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/83923434
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/83923434
Branch: refs/heads/master
Commit: 8392343410d501f2fa772b4e6c1ab3d00ec167c6
Parents: d549178
Author: Stefan Bodewig <bo...@apache.org>
Authored: Fri Jan 5 17:54:05 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri Jan 5 17:54:05 2018 +0100
----------------------------------------------------------------------
.../compress/archivers/zip/ZipArchiveEntry.java | 33 ++++++++++++++++++++
1 file changed, 33 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/83923434/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
index 846b6f7..bbb451b 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
@@ -59,14 +59,47 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
private static final int SHORT_SHIFT = 16;
private static final byte[] EMPTY = new byte[0];
+ /**
+ * Indicates how the name of this entry has been determined.
+ * @since 1.16
+ */
public enum NameSource {
+ /**
+ * The name has been read from the archive using the encoding
+ * of the archive specified when creating the {@link
+ * ZipArchiveInputStream} or {@link ZipFile} (defaults to the
+ * platform's default encoding).
+ */
NAME,
+ /**
+ * The name has been read from the archive and the archive
+ * specified the EFS flag which indicates the name has been
+ * encoded as UTF-8.
+ */
NAME_WITH_EFS_FLAG,
+ /**
+ * The name has been read from an {@link UnicodePathExtraField
+ * Unicode Extra Field}.
+ */
UNICODE_EXTRA_FIELD
}
+ /**
+ * Indicates how the comment of this entry has been determined.
+ * @since 1.16
+ */
public enum CommentSource {
+ /**
+ * The comment has been read from the archive using the encoding
+ * of the archive specified when creating the {@link
+ * ZipArchiveInputStream} or {@link ZipFile} (defaults to the
+ * platform's default encoding).
+ */
COMMENT,
+ /**
+ * The comment has been read from an {@link UnicodeCommentExtraField
+ * Unicode Extra Field}.
+ */
UNICODE_EXTRA_FIELD
}
[2/9] commons-compress git commit: Provide information about presence
of Unicode name and comment in ZipArchiveEntry
Posted by bo...@apache.org.
Provide information about presence of Unicode name and comment in ZipArchiveEntry
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/e83b4d84
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/e83b4d84
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/e83b4d84
Branch: refs/heads/master
Commit: e83b4d8484cdb3dcef44ce3aede866663b526158
Parents: c36fef5
Author: Damiano Albani <da...@gmail.com>
Authored: Mon Nov 20 16:46:42 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri Jan 5 17:25:27 2018 +0100
----------------------------------------------------------------------
.../compress/archivers/zip/ZipArchiveEntry.java | 19 ++++++++++++++++++-
.../commons/compress/archivers/zip/ZipUtil.java | 2 ++
2 files changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/e83b4d84/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
index d744a04..13eae15 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
@@ -98,7 +98,8 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
private long localHeaderOffset = OFFSET_UNKNOWN;
private long dataOffset = OFFSET_UNKNOWN;
private boolean isStreamContiguous = false;
-
+ private boolean hasUnicodeName = false;
+ private boolean hasUnicodeComment = false;
/**
* Creates a new zip entry with the specified name.
@@ -927,4 +928,20 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
public void setRawFlag(final int rawFlag) {
this.rawFlag = rawFlag;
}
+
+ public boolean hasUnicodeName() {
+ return hasUnicodeName;
+ }
+
+ public void setHasUnicodeName(boolean hasUnicodeName) {
+ this.hasUnicodeName = hasUnicodeName;
+ }
+
+ public boolean hasUnicodeComment() {
+ return hasUnicodeComment;
+ }
+
+ public void setHasUnicodeComment(boolean hasUnicodeComment) {
+ this.hasUnicodeComment = hasUnicodeComment;
+ }
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/e83b4d84/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
index 97fd341..11f7315 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
@@ -239,6 +239,7 @@ public abstract class ZipUtil {
originalNameBytes);
if (newName != null && !originalName.equals(newName)) {
ze.setName(newName);
+ ze.setHasUnicodeName(true);
}
if (commentBytes != null && commentBytes.length > 0) {
@@ -248,6 +249,7 @@ public abstract class ZipUtil {
getUnicodeStringIfOriginalMatches(cmt, commentBytes);
if (newComment != null) {
ze.setComment(newComment);
+ ze.setHasUnicodeComment(true);
}
}
}
[9/9] commons-compress git commit: COMPRESS-429 the reason for the
name check no longer exists
Posted by bo...@apache.org.
COMPRESS-429 the reason for the name check no longer exists
It used to be there to avoid unnecessary updates of ZipFile's map of
entry name => entry but the handling in ZipFile has been changed to
only add entries after all fields have been resolved in later
revisions.
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/ced2075c
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/ced2075c
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/ced2075c
Branch: refs/heads/master
Commit: ced2075cabcda4e5fb2db60e88cdf87bf815d24b
Parents: c290609
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun Jan 7 10:29:26 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun Jan 7 10:29:26 2018 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/compress/archivers/zip/ZipUtil.java | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ced2075c/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
index 783835c..34ee233 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
@@ -238,9 +238,7 @@ public abstract class ZipUtil {
final String newName = getUnicodeStringIfOriginalMatches(name,
originalNameBytes);
if (newName != null) {
- if (!originalName.equals(newName)) {
- ze.setName(newName);
- }
+ ze.setName(newName);
ze.setNameSource(ZipArchiveEntry.NameSource.UNICODE_EXTRA_FIELD);
}
[6/9] commons-compress git commit: COMPRESS-429 tests
Posted by bo...@apache.org.
COMPRESS-429 tests
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/0517c7f2
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/0517c7f2
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/0517c7f2
Branch: refs/heads/master
Commit: 0517c7f2e4ea6806098453b295f230dd42a8f510
Parents: 8392343
Author: Stefan Bodewig <bo...@apache.org>
Authored: Fri Jan 5 17:54:15 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri Jan 5 17:54:15 2018 +0100
----------------------------------------------------------------------
.../zip/ZipArchiveInputStreamTest.java | 33 ++++++++++++++++++++
.../compress/archivers/zip/ZipFileTest.java | 25 +++++++++++++++
2 files changed, 58 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0517c7f2/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
index a0a5c50..4c654c0 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
@@ -272,6 +272,23 @@ public class ZipArchiveInputStreamTest {
}
}
+ @Test
+ public void nameSourceDefaultsToName() throws Exception {
+ nameSource("bla.zip", "test1.xml", ZipArchiveEntry.NameSource.NAME);
+ }
+
+ @Test
+ public void nameSourceIsSetToUnicodeExtraField() throws Exception {
+ nameSource("utf8-winzip-test.zip", "\u20AC_for_Dollar.txt",
+ ZipArchiveEntry.NameSource.UNICODE_EXTRA_FIELD);
+ }
+
+ @Test
+ public void nameSourceIsSetToEFS() throws Exception {
+ nameSource("utf8-7zip-test.zip", "\u20AC_for_Dollar.txt", 3,
+ ZipArchiveEntry.NameSource.NAME_WITH_EFS_FLAG);
+ }
+
private static byte[] readEntry(ZipArchiveInputStream zip, ZipArchiveEntry zae) throws IOException {
final int len = (int)zae.getSize();
final byte[] buff = new byte[len];
@@ -279,4 +296,20 @@ public class ZipArchiveInputStreamTest {
return buff;
}
+
+ private static void nameSource(String archive, String entry, ZipArchiveEntry.NameSource expected) throws Exception {
+ nameSource(archive, entry, 1, expected);
+ }
+
+ private static void nameSource(String archive, String entry, int entryNo, ZipArchiveEntry.NameSource expected)
+ throws Exception {
+ try (ZipArchiveInputStream zis = new ZipArchiveInputStream(new FileInputStream(getFile(archive)))) {
+ ZipArchiveEntry ze;
+ do {
+ ze = zis.getNextZipEntry();
+ } while (--entryNo > 0);
+ assertEquals(entry, ze.getName());
+ assertEquals(expected, ze.getNameSource());
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0517c7f2/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
index 87a3ded..a6170b1 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
@@ -581,6 +581,23 @@ public class ZipFileTest {
entry.setAlignment(3);
}
+ @Test
+ public void nameSourceDefaultsToName() throws Exception {
+ nameSource("bla.zip", "test1.xml", ZipArchiveEntry.NameSource.NAME);
+ }
+
+ @Test
+ public void nameSourceIsSetToUnicodeExtraField() throws Exception {
+ nameSource("utf8-winzip-test.zip", "\u20AC_for_Dollar.txt",
+ ZipArchiveEntry.NameSource.UNICODE_EXTRA_FIELD);
+ }
+
+ @Test
+ public void nameSourceIsSetToEFS() throws Exception {
+ nameSource("utf8-7zip-test.zip", "\u20AC_for_Dollar.txt",
+ ZipArchiveEntry.NameSource.NAME_WITH_EFS_FLAG);
+ }
+
private void assertAllReadMethods(byte[] expected, ZipFile zipFile, ZipArchiveEntry entry) {
// simple IOUtil read
try (InputStream stream = zf.getInputStream(entry)) {
@@ -673,4 +690,12 @@ public class ZipFileTest {
+ expectedName + ".java",
ze.getName());
}
+
+ private static void nameSource(String archive, String entry, ZipArchiveEntry.NameSource expected) throws Exception {
+ try (ZipFile zf = new ZipFile(getFile(archive))) {
+ ZipArchiveEntry ze = zf.getEntry(entry);
+ assertEquals(entry, ze.getName());
+ assertEquals(expected, ze.getNameSource());
+ }
+ }
}
[4/9] commons-compress git commit: COMPRESS-429 also set NameSource
from within stream
Posted by bo...@apache.org.
COMPRESS-429 also set NameSource from within stream
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/d549178f
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/d549178f
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/d549178f
Branch: refs/heads/master
Commit: d549178f36aaf95fd1aa2fe6a3c1403c095929b2
Parents: 9d721a0
Author: Stefan Bodewig <bo...@apache.org>
Authored: Fri Jan 5 17:50:22 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri Jan 5 17:50:22 2018 +0100
----------------------------------------------------------------------
.../commons/compress/archivers/zip/ZipArchiveInputStream.java | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d549178f/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
index 54b69ae..04fc487 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
@@ -297,6 +297,9 @@ public class ZipArchiveInputStream extends ArchiveInputStream {
final byte[] fileName = new byte[fileNameLen];
readFully(fileName);
current.entry.setName(entryEncoding.decode(fileName), fileName);
+ if (hasUTF8Flag) {
+ current.entry.setNameSource(ZipArchiveEntry.NameSource.NAME_WITH_EFS_FLAG);
+ }
final byte[] extraData = new byte[extraLen];
readFully(extraData);
[3/9] commons-compress git commit: revert change to imports
Posted by bo...@apache.org.
revert change to imports
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/9d721a0a
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/9d721a0a
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/9d721a0a
Branch: refs/heads/master
Commit: 9d721a0af60c54509b01c2daf5f3bac0dbba0a93
Parents: f488eba
Author: Stefan Bodewig <bo...@apache.org>
Authored: Fri Jan 5 17:27:35 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri Jan 5 17:27:35 2018 +0100
----------------------------------------------------------------------
.../commons/compress/archivers/zip/ZipFile.java | 29 ++++++++++++++++----
1 file changed, 23 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/9d721a0a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
index 1e30f31..75e5cd5 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
@@ -17,21 +17,38 @@
*/
package org.apache.commons.compress.archivers.zip;
-import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
-import org.apache.commons.compress.utils.IOUtils;
-
-import java.io.*;
+import java.io.BufferedInputStream;
+import java.io.Closeable;
+import java.io.EOFException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import java.util.zip.ZipException;
-import static org.apache.commons.compress.archivers.zip.ZipConstants.*;
+import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
+import org.apache.commons.compress.utils.IOUtils;
+
+import static org.apache.commons.compress.archivers.zip.ZipConstants.DWORD;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.SHORT;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.WORD;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.ZIP64_MAGIC;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.ZIP64_MAGIC_SHORT;
/**
* Replacement for <code>java.util.ZipFile</code>.
[8/9] commons-compress git commit: COMPRESS-429 set namesource to
extra field even if names match
Posted by bo...@apache.org.
COMPRESS-429 set namesource to extra field even if names match
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/c2906092
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/c2906092
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/c2906092
Branch: refs/heads/master
Commit: c2906092f9fab7bb718ba177d521ae152d4d9f1c
Parents: eb32d62
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun Jan 7 10:22:25 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun Jan 7 10:22:25 2018 +0100
----------------------------------------------------------------------
.../org/apache/commons/compress/archivers/zip/ZipUtil.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c2906092/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
index 6342cd1..783835c 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
@@ -237,8 +237,10 @@ public abstract class ZipUtil {
final String originalName = ze.getName();
final String newName = getUnicodeStringIfOriginalMatches(name,
originalNameBytes);
- if (newName != null && !originalName.equals(newName)) {
- ze.setName(newName);
+ if (newName != null) {
+ if (!originalName.equals(newName)) {
+ ze.setName(newName);
+ }
ze.setNameSource(ZipArchiveEntry.NameSource.UNICODE_EXTRA_FIELD);
}