commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [1/6] commons-compress git commit: Expose source of name/comment field value via dedicated methods
Date Fri, 05 Jan 2018 16:54:42 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/COMPRESS-429 [created] 0517c7f2e


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/COMPRESS-429
Commit: f488eba11289fae758646a21f86b2ad6c4156538
Parents: e83b4d8
Author: Damiano Albani <damiano.albani@gmail.com>
Authored: Tue Dec 12 17:07:24 2017 +0100
Committer: Stefan Bodewig <bodewig@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);
             }
         }
     }


Mime
View raw message