commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [6/6] commons-compress git commit: COMPRESS-391 some tweaks
Date Thu, 11 May 2017 18:15:33 GMT
COMPRESS-391 some tweaks


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/fef18a23
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/fef18a23
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/fef18a23

Branch: refs/heads/master
Commit: fef18a23d3b09025e0ddc3733334a4587c3af712
Parents: f2af9f0
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Thu May 11 20:15:10 2017 +0200
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Thu May 11 20:15:10 2017 +0200

----------------------------------------------------------------------
 .../archivers/zip/ResourceAlignmentExtraField.java  | 16 ++++++++++------
 .../compress/archivers/zip/ZipArchiveEntry.java     |  2 ++
 .../archivers/zip/ZipArchiveOutputStream.java       | 16 ++++++----------
 .../compress/archivers/zip/ZipExtraField.java       |  6 ++++++
 .../commons/compress/archivers/zip/ZipShort.java    |  4 ++++
 5 files changed, 28 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/fef18a23/src/main/java/org/apache/commons/compress/archivers/zip/ResourceAlignmentExtraField.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ResourceAlignmentExtraField.java
b/src/main/java/org/apache/commons/compress/archivers/zip/ResourceAlignmentExtraField.java
index a9f8748..79e20f6 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ResourceAlignmentExtraField.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ResourceAlignmentExtraField.java
@@ -44,6 +44,8 @@ public class ResourceAlignmentExtraField implements ZipExtraField {
 
     public static final int BASE_SIZE = 2;
 
+    private static final int ALLOW_METHOD_MESSAGE_CHANGE_FLAG = 0x8000;
+
     private short alignment;
 
     private boolean allowMethodChange;
@@ -106,14 +108,15 @@ public class ResourceAlignmentExtraField implements ZipExtraField {
 
     @Override
     public byte[] getLocalFileDataData() {
-        byte[] content = new byte[2+padding];
-        ZipShort.putShort(alignment | (allowMethodChange ? 0x8000 : 0), content, 0);
+        byte[] content = new byte[BASE_SIZE + padding];
+        ZipShort.putShort(alignment | (allowMethodChange ? ALLOW_METHOD_MESSAGE_CHANGE_FLAG
: 0),
+                          content, 0);
         return content;
     }
 
     @Override
     public byte[] getCentralDirectoryData() {
-        return ZipShort.getBytes(alignment | (allowMethodChange ? 0x8000 : 0));
+        return ZipShort.getBytes(alignment | (allowMethodChange ? ALLOW_METHOD_MESSAGE_CHANGE_FLAG
: 0));
     }
 
     @Override
@@ -124,10 +127,11 @@ public class ResourceAlignmentExtraField implements ZipExtraField {
 
     @Override
     public void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) throws
ZipException {
-        if (length < 2)
+        if (length < BASE_SIZE) {
             throw new ZipException("Too short content for ResourceAlignmentExtraField (0xa11e):
" + length);
+        }
         int alignmentValue = ZipShort.getValue(buffer, offset);
-        this.alignment = (short) (alignmentValue&0x7fff);
-        this.allowMethodChange = (alignmentValue&0x8000) != 0;
+        this.alignment = (short) (alignmentValue & (ALLOW_METHOD_MESSAGE_CHANGE_FLAG
- 1));
+        this.allowMethodChange = (alignmentValue & ALLOW_METHOD_MESSAGE_CHANGE_FLAG)
!= 0;
     }
 }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/fef18a23/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 ffcb953..69e4990 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
@@ -328,6 +328,7 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
      *
      * @return
      *      alignment for this entry.
+     * @since 1.14
      */
     protected int getAlignment() {
         return this.alignment;
@@ -338,6 +339,7 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
      *
      * @param alignment
      *      requested alignment, 0 for default.
+     * @since 1.14
      */
     public void setAlignment(int alignment) {
         if ((alignment & (alignment - 1)) != 0 || alignment > 0xffff) {

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/fef18a23/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
index 5649af3..c667356 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
@@ -142,11 +142,6 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream {
     @Deprecated
     public static final int EFS_FLAG = GeneralPurposeBit.UFT8_NAMES_FLAG;
 
-    /**
-     * Size of an extra field field header (id + length).
-     */
-    public static final int EXTRAFIELD_HEADER_SIZE = 4;
-
     private static final byte[] EMPTY = new byte[0];
 
     /**
@@ -1043,9 +1038,10 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream {
     private byte[] createLocalFileHeader(final ZipArchiveEntry ze, final ByteBuffer name,
final boolean encodable,
                                          final boolean phased, long archiveOffset) throws
IOException {
         ResourceAlignmentExtraField oldAlignmentEx =
-                        (ResourceAlignmentExtraField) ze.getExtraField(ResourceAlignmentExtraField.ID);
-        if (oldAlignmentEx != null)
+            (ResourceAlignmentExtraField) ze.getExtraField(ResourceAlignmentExtraField.ID);
+        if (oldAlignmentEx != null) {
             ze.removeExtraField(ResourceAlignmentExtraField.ID);
+        }
 
         int alignment = ze.getAlignment();
         if (alignment <= 0 && oldAlignmentEx != null) {
@@ -1057,16 +1053,16 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream {
                             name.limit() - name.position() +
                             ze.getLocalFileDataExtra().length;
 
-            int padding = (int) ((-archiveOffset - oldLength - EXTRAFIELD_HEADER_SIZE
+            int padding = (int) ((-archiveOffset - oldLength - ZipExtraField.EXTRAFIELD_HEADER_SIZE
                             - ResourceAlignmentExtraField.BASE_SIZE) &
                             (alignment - 1));
             ze.addExtraField(new ResourceAlignmentExtraField(alignment,
                             oldAlignmentEx != null ? oldAlignmentEx.allowMethodChange() :
false, padding));
         }
 
-        byte[] extra = ze.getLocalFileDataExtra();
+        final byte[] extra = ze.getLocalFileDataExtra();
         final int nameLen = name.limit() - name.position();
-        int len = LFH_FILENAME_OFFSET + nameLen + extra.length;
+        final int len = LFH_FILENAME_OFFSET + nameLen + extra.length;
         final byte[] buf = new byte[len];
 
         System.arraycopy(LFH_SIG,  0, buf, LFH_SIG_OFFSET, WORD);

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/fef18a23/src/main/java/org/apache/commons/compress/archivers/zip/ZipExtraField.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipExtraField.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipExtraField.java
index 3149774..2c44b2a 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipExtraField.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipExtraField.java
@@ -32,6 +32,12 @@ import java.util.zip.ZipException;
  */
 public interface ZipExtraField {
     /**
+     * Size of an extra field field header (id + length).
+     * @since 1.14
+     */
+    int EXTRAFIELD_HEADER_SIZE = 4;
+
+    /**
      * The Header-ID.
      *
      * @return The HeaderId value

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/fef18a23/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
index 65acf21..ccb5094 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
@@ -27,6 +27,10 @@ import org.apache.commons.compress.utils.ByteUtils;
  * @Immutable
  */
 public final class ZipShort implements Cloneable, Serializable {
+    /**
+     * ZipShort with a value of 0.
+     * @since 1.14
+     */
     public static final ZipShort ZERO = new ZipShort(0);
 
     private static final long serialVersionUID = 1L;


Mime
View raw message