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 2017/07/04 08:56:45 UTC

[2/6] commons-compress git commit: COMPRESS-416 Add signed 32bit int constructor and accessor to ZipLong

COMPRESS-416 Add signed 32bit int constructor and accessor to ZipLong

Signed-off-by: Simon Spero <se...@gmail.com>


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

Branch: refs/heads/master
Commit: d0595b7121f57f1f49fe7fdc384479dd73ad64f5
Parents: 992911d
Author: Simon Spero <se...@gmail.com>
Authored: Mon Jul 3 18:24:55 2017 -0400
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Jul 4 08:51:32 2017 +0200

----------------------------------------------------------------------
 .../commons/compress/archivers/zip/ZipLong.java   | 18 ++++++++++++++++--
 .../compress/archivers/zip/ZipLongTest.java       | 13 ++++++++++---
 2 files changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d0595b71/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
index 2976183..07da7d5 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
@@ -17,10 +17,10 @@
  */
 package org.apache.commons.compress.archivers.zip;
 
-import java.io.Serializable;
-
 import org.apache.commons.compress.utils.ByteUtils;
 
+import java.io.Serializable;
+
 import static org.apache.commons.compress.archivers.zip.ZipConstants.WORD;
 
 /**
@@ -82,6 +82,14 @@ public final class ZipLong implements Cloneable, Serializable {
     }
 
     /**
+     * create instance from a java int.
+      * @param value
+     */
+    public ZipLong(int value) {
+        this.value = value;
+    }
+
+    /**
      * Create instance from bytes.
      * @param bytes the bytes to store as a ZipLong
      */
@@ -115,6 +123,12 @@ public final class ZipLong implements Cloneable, Serializable {
     }
 
     /**
+     * Get value as a (signed) java int
+     * @return
+     */
+    public int getIntValue() { return (int)value;}
+
+    /**
      * Get value as four bytes in big endian byte order.
      * @param value the value to convert
      * @return value as four bytes in big endian byte order

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d0595b71/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java
index f72d886..75709fd 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java
@@ -18,10 +18,10 @@
 
 package org.apache.commons.compress.archivers.zip;
 
-import static org.junit.Assert.*;
-
 import org.junit.Test;
 
+import static org.junit.Assert.*;
+
 /**
  * JUnit testcases for org.apache.commons.compress.archivers.zip.ZipLong.
  *
@@ -90,8 +90,15 @@ public class ZipLongTest {
      */
     @Test
     public void testSign() {
-        final ZipLong zl = new ZipLong(new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF});
+         ZipLong zl = new ZipLong(new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF});
         assertEquals(0x00000000FFFFFFFFl, zl.getValue());
+        assertEquals(-1,zl.getIntValue());
+
+        zl = new ZipLong(0xFFFF_FFFFL);
+        assertEquals(0x00000000FFFFFFFFl, zl.getValue());
+        zl = new ZipLong(0xFFFF_FFFF);
+        assertEquals(0xFFFF_FFFF_FFFF_FFFFL, zl.getValue());
+
     }
 
     @Test